Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4551)

Unified Diff: chrome/browser/ui/apps/chrome_shell_window_delegate.cc

Issue 16702003: Move ShellWindow into apps component. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Feedback Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/apps/chrome_shell_window_delegate.cc
diff --git a/chrome/browser/ui/apps/chrome_shell_window_delegate.cc b/chrome/browser/ui/apps/chrome_shell_window_delegate.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2e335cde33a31fdd09f310ba9c8598ccea078048
--- /dev/null
+++ b/chrome/browser/ui/apps/chrome_shell_window_delegate.cc
@@ -0,0 +1,154 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/ui/apps/chrome_shell_window_delegate.h"
+
+#include "base/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/ui/browser.h"
+#include "chrome/browser/ui/browser_dialogs.h"
+#include "chrome/browser/ui/browser_finder.h"
+#include "chrome/browser/ui/browser_tabstrip.h"
+#include "chrome/browser/ui/browser_window.h"
+#include "chrome/common/render_messages.h"
+#include "content/public/browser/render_view_host.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/browser/web_contents_view.h"
+
+#if defined(USE_ASH)
+#include "ash/launcher/launcher_types.h"
+#endif
+
+namespace chrome {
+
+namespace {
+
+static bool disable_external_open_for_testing_ = false;
sky 2013/06/19 14:16:04 no need for static here.
benwells 2013/06/25 08:36:03 Done.
+
+class ShellWindowLinkDelegate : public content::WebContentsDelegate {
+ private:
+ virtual content::WebContents* OpenURLFromTab(
+ content::WebContents* source,
+ const content::OpenURLParams& params) OVERRIDE;
+};
sky 2013/06/19 14:16:04 DISALLOW_...
benwells 2013/06/25 08:36:03 Done.
+
+content::WebContents* ShellWindowLinkDelegate::OpenURLFromTab(
+ content::WebContents* source,
+ const content::OpenURLParams& params) {
+ platform_util::OpenExternal(params.url);
+ delete source;
sky 2013/06/19 14:16:04 Are you sure this doesn't crash? In particular del
benwells 2013/06/25 08:36:03 I'm moving this code from shell_window.cc. The que
Ken Rockot(use gerrit already) 2013/06/25 17:18:11 source is always a fresh blank WebContents, so in
sky 2013/06/25 17:53:37 It doesn't matter than source is a fresh webconten
Ken Rockot(use gerrit already) 2013/06/25 22:25:51 The call site in this case is always WebContentsIm
+ return NULL;
+}
+
+} // namespace
+
+ChromeShellWindowDelegate::~ChromeShellWindowDelegate() {}
+
+void ChromeShellWindowDelegate::DisableExternalOpenForTesting() {
+ disable_external_open_for_testing_ = true;
+}
+
+void ChromeShellWindowDelegate::InitWebContents(
+ content::WebContents* web_contents) {
+ FaviconTabHelper::CreateForWebContents(web_contents);
+}
+
+content::WebContents* ChromeShellWindowDelegate::OpenURLFromTab(
+ Profile* profile,
+ content::WebContents* source,
+ const content::OpenURLParams& params) {
+ // Force all links to open in a new tab, even if they were trying to open a
+ // window.
+ chrome::NavigateParams new_tab_params(
+ static_cast<Browser*>(NULL), params.url, params.transition);
+ new_tab_params.disposition = params.disposition == NEW_BACKGROUND_TAB ?
+ params.disposition : NEW_FOREGROUND_TAB;
+ new_tab_params.initiating_profile = profile;
+ chrome::Navigate(&new_tab_params);
+
+ return new_tab_params.target_contents;
+}
+
+void ChromeShellWindowDelegate::AddNewContents(
+ Profile* profile,
+ content::WebContents* new_contents,
+ WindowOpenDisposition disposition,
+ const gfx::Rect& initial_pos,
+ bool user_gesture,
+ bool* was_blocked) {
+#if defined(OS_MACOSX) || defined(OS_WIN) || \
+ (defined(OS_LINUX) && !defined(OS_CHROMEOS))
+ if (disable_external_open_for_testing_) {
+ Browser* browser =
+ chrome::FindOrCreateTabbedBrowser(profile, chrome::GetActiveDesktop());
sky 2013/06/19 14:16:04 If this creates a new browser how does it get show
benwells 2013/06/25 08:36:03 Again, I'm just moving this code from shell_window
Ken Rockot(use gerrit already) 2013/06/25 17:18:11 The following AddWebContents calls chrome::Navigat
+ // Force all links to open in a new tab, even if they were trying to open a
+ // new window.
+ disposition =
+ disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB;
+ chrome::AddWebContents(browser, NULL, new_contents, disposition,
+ initial_pos, user_gesture, was_blocked);
+ } else {
+ new_contents->SetDelegate(new ShellWindowLinkDelegate());
+ }
+#else
+ Browser* browser =
+ chrome::FindOrCreateTabbedBrowser(profile, chrome::GetActiveDesktop());
sky 2013/06/19 14:16:04 Same question here. 98-105 look the same as 86-105
benwells 2013/06/25 08:36:03 The ifdef is needed but I've rearranged so the cod
+ // Force all links to open in a new tab, even if they were trying to open a
+ // new window.
+ disposition =
+ disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB;
+ chrome::AddWebContents(browser, NULL, new_contents, disposition, initial_pos,
+ user_gesture, was_blocked);
+#endif
+}
+
+content::ColorChooser* ChromeShellWindowDelegate::ShowColorChooser(
+ content::WebContents* web_contents,
+ SkColor initial_color) {
+ return chrome::ShowColorChooser(web_contents, initial_color);
+}
+
+void ChromeShellWindowDelegate::RunFileChooser(
+ content::WebContents* tab,
+ const content::FileChooserParams& params) {
+ FileSelectHelper::RunFileChooser(tab, params);
+}
+
+void ChromeShellWindowDelegate::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 ChromeShellWindowDelegate::PreferredIconSize() {
+#if defined(USE_ASH)
+ return ash::kLauncherPreferredSize;
+#else
+ return extension_misc::EXTENSION_ICON_SMALL;
+#endif
+}
+
+void ChromeShellWindowDelegate::SetWebContentsBlocked(
+ content::WebContents* web_contents,
+ bool blocked) {
+ // RenderViewHost may be NULL during shutdown.
+ content::RenderViewHost* host = web_contents->GetRenderViewHost();
+ if (host) {
+ host->Send(new ChromeViewMsg_SetVisuallyDeemphasized(
+ host->GetRoutingID(), blocked));
+ }
+}
+
+bool ChromeShellWindowDelegate::IsWebContentsVisible(
+ content::WebContents* web_contents) {
+ return platform_util::IsVisible(web_contents->GetView()->GetNativeView());
+}
+
+} // namespace chrome

Powered by Google App Engine
This is Rietveld 408576698