This source file includes following definitions.
- OpenURLFromTabInternal
- params_
- SetDefaultWebClientUIState
- IsOwnedByWorker
- NewWindowContentsDelegate
- NewWindowContentsDelegate
- OpenURLFromTab
- DisableExternalOpenForTesting
- InitWebContents
- CreateNativeAppWindow
- OpenURLFromTab
- AddNewContents
- ShowColorChooser
- RunFileChooser
- RequestMediaAccessPermission
- PreferredIconSize
- SetWebContentsBlocked
- IsWebContentsVisible
#include "chrome/browser/ui/apps/chrome_app_window_delegate.h"
#include "base/memory/scoped_ptr.h"
#include "base/strings/stringprintf.h"
#include "chrome/browser/favicon/favicon_tab_helper.h"
#include "chrome/browser/file_select_helper.h"
#include "chrome/browser/media/media_capture_devices_dispatcher.h"
#include "chrome/browser/platform_util.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/shell_integration.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_dialogs.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
#include "chrome/common/render_messages.h"
#include "content/public/browser/browser_context.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_delegate.h"
#include "content/public/browser/web_contents_view.h"
#include "extensions/common/constants.h"
#if defined(USE_ASH)
#include "ash/shelf/shelf_constants.h"
#endif
#if defined(ENABLE_PRINTING)
#if defined(ENABLE_FULL_PRINTING)
#include "chrome/browser/printing/print_preview_message_handler.h"
#include "chrome/browser/printing/print_view_manager.h"
#else
#include "chrome/browser/printing/print_view_manager_basic.h"
#endif
#endif
namespace {
bool disable_external_open_for_testing_ = false;
content::WebContents* OpenURLFromTabInternal(
content::BrowserContext* context,
const content::OpenURLParams& params) {
chrome::NavigateParams new_tab_params(
static_cast<Browser*>(NULL), params.url, params.transition);
if (params.disposition == NEW_BACKGROUND_TAB) {
new_tab_params.disposition = NEW_BACKGROUND_TAB;
} else {
new_tab_params.disposition = NEW_FOREGROUND_TAB;
new_tab_params.window_action = chrome::NavigateParams::SHOW_WINDOW;
}
new_tab_params.initiating_profile = Profile::FromBrowserContext(context);
chrome::Navigate(&new_tab_params);
return new_tab_params.target_contents;
}
class OpenURLFromTabBasedOnBrowserDefault
: public ShellIntegration::DefaultWebClientObserver {
public:
OpenURLFromTabBasedOnBrowserDefault(scoped_ptr<content::WebContents> source,
const content::OpenURLParams& params)
: source_(source.Pass()), params_(params) {}
virtual void SetDefaultWebClientUIState(
ShellIntegration::DefaultWebClientUIState state) OVERRIDE {
Profile* profile =
Profile::FromBrowserContext(source_->GetBrowserContext());
DCHECK(profile);
if (!profile)
return;
switch (state) {
case ShellIntegration::STATE_PROCESSING:
break;
case ShellIntegration::STATE_IS_DEFAULT:
OpenURLFromTabInternal(profile, params_);
break;
case ShellIntegration::STATE_NOT_DEFAULT:
case ShellIntegration::STATE_UNKNOWN:
platform_util::OpenExternal(profile, params_.url);
break;
}
}
virtual bool IsOwnedByWorker() OVERRIDE { return true; }
private:
scoped_ptr<content::WebContents> source_;
const content::OpenURLParams params_;
};
}
class ChromeAppWindowDelegate::NewWindowContentsDelegate
: public content::WebContentsDelegate {
public:
NewWindowContentsDelegate() {}
virtual ~NewWindowContentsDelegate() {}
virtual content::WebContents* OpenURLFromTab(
content::WebContents* source,
const content::OpenURLParams& params) OVERRIDE;
private:
DISALLOW_COPY_AND_ASSIGN(NewWindowContentsDelegate);
};
content::WebContents*
ChromeAppWindowDelegate::NewWindowContentsDelegate::OpenURLFromTab(
content::WebContents* source,
const content::OpenURLParams& params) {
if (source) {
scoped_ptr<content::WebContents> owned_source(source);
scoped_refptr<ShellIntegration::DefaultWebClientWorker>
check_if_default_browser_worker =
new ShellIntegration::DefaultBrowserWorker(
new OpenURLFromTabBasedOnBrowserDefault(owned_source.Pass(),
params));
check_if_default_browser_worker->StartCheckIsDefault();
}
return NULL;
}
ChromeAppWindowDelegate::ChromeAppWindowDelegate()
: new_window_contents_delegate_(new NewWindowContentsDelegate()) {}
ChromeAppWindowDelegate::~ChromeAppWindowDelegate() {}
void ChromeAppWindowDelegate::DisableExternalOpenForTesting() {
disable_external_open_for_testing_ = true;
}
void ChromeAppWindowDelegate::InitWebContents(
content::WebContents* web_contents) {
FaviconTabHelper::CreateForWebContents(web_contents);
#if defined(ENABLE_PRINTING)
#if defined(ENABLE_FULL_PRINTING)
printing::PrintViewManager::CreateForWebContents(web_contents);
printing::PrintPreviewMessageHandler::CreateForWebContents(web_contents);
#else
printing::PrintViewManagerBasic::CreateForWebContents(web_contents);
#endif
#endif
}
apps::NativeAppWindow* ChromeAppWindowDelegate::CreateNativeAppWindow(
apps::AppWindow* window,
const apps::AppWindow::CreateParams& params) {
return CreateNativeAppWindowImpl(window, params);
}
content::WebContents* ChromeAppWindowDelegate::OpenURLFromTab(
content::BrowserContext* context,
content::WebContents* source,
const content::OpenURLParams& params) {
return OpenURLFromTabInternal(context, params);
}
void ChromeAppWindowDelegate::AddNewContents(content::BrowserContext* context,
content::WebContents* new_contents,
WindowOpenDisposition disposition,
const gfx::Rect& initial_pos,
bool user_gesture,
bool* was_blocked) {
if (!disable_external_open_for_testing_) {
new_contents->SetDelegate(new_window_contents_delegate_.get());
return;
}
chrome::ScopedTabbedBrowserDisplayer displayer(
Profile::FromBrowserContext(context), chrome::GetActiveDesktop());
disposition =
disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB;
chrome::AddWebContents(displayer.browser(), NULL, new_contents, disposition,
initial_pos, user_gesture, was_blocked);
}
content::ColorChooser* ChromeAppWindowDelegate::ShowColorChooser(
content::WebContents* web_contents,
SkColor initial_color) {
return chrome::ShowColorChooser(web_contents, initial_color);
}
void ChromeAppWindowDelegate::RunFileChooser(
content::WebContents* tab,
const content::FileChooserParams& params) {
FileSelectHelper::RunFileChooser(tab, params);
}
void ChromeAppWindowDelegate::RequestMediaAccessPermission(
content::WebContents* web_contents,
const content::MediaStreamRequest& request,
const content::MediaResponseCallback& callback,
const extensions::Extension* extension) {
MediaCaptureDevicesDispatcher::GetInstance()->ProcessMediaAccessRequest(
web_contents, request, callback, extension);
}
int ChromeAppWindowDelegate::PreferredIconSize() {
#if defined(USE_ASH)
return ash::kShelfPreferredSize;
#else
return extension_misc::EXTENSION_ICON_SMALL;
#endif
}
void ChromeAppWindowDelegate::SetWebContentsBlocked(
content::WebContents* web_contents,
bool blocked) {
content::RenderViewHost* host = web_contents->GetRenderViewHost();
if (host) {
host->Send(new ChromeViewMsg_SetVisuallyDeemphasized(
host->GetRoutingID(), blocked));
}
}
bool ChromeAppWindowDelegate::IsWebContentsVisible(
content::WebContents* web_contents) {
return platform_util::IsVisible(web_contents->GetView()->GetNativeView());
}