summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorerikkay@google.com <erikkay@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-13 15:46:41 +0000
committererikkay@google.com <erikkay@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-04-13 15:46:41 +0000
commit8830998f7436edb5aabd1a3465d7ba5e7b77fd05 (patch)
tree7d90b836f05d2b01b1a68b053aeab068efa73501 /chrome/browser
parent0d34712130aaa3982dabb0a34e96a2be85a5f2e1 (diff)
downloadchromium_src-8830998f7436edb5aabd1a3465d7ba5e7b77fd05.zip
chromium_src-8830998f7436edb5aabd1a3465d7ba5e7b77fd05.tar.gz
chromium_src-8830998f7436edb5aabd1a3465d7ba5e7b77fd05.tar.bz2
Hook up a bit more plumbing to ExtensionView which should allow popup windows and widgets to work.Add in a quick hack that lets you bring up the web inspector.
Review URL: http://codereview.chromium.org/67029 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13595 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/browser.vcproj18
-rwxr-xr-xchrome/browser/extensions/extension_process_manager.cc7
-rwxr-xr-xchrome/browser/extensions/extension_process_manager.h3
-rwxr-xr-xchrome/browser/extensions/extension_view.cc86
-rwxr-xr-xchrome/browser/extensions/extension_view.h36
-rwxr-xr-xchrome/browser/extensions/extension_view_unittest.cc7
-rw-r--r--chrome/browser/tab_contents/render_view_host_delegate_helper.cc196
-rw-r--r--chrome/browser/tab_contents/render_view_host_delegate_helper.h68
-rw-r--r--chrome/browser/tab_contents/web_contents.cc91
-rw-r--r--chrome/browser/tab_contents/web_contents_view.cc98
-rw-r--r--chrome/browser/tab_contents/web_contents_view.h4
-rw-r--r--chrome/browser/views/bookmark_bar_view.cc6
-rw-r--r--chrome/browser/views/hwnd_html_view.h2
13 files changed, 440 insertions, 182 deletions
diff --git a/chrome/browser/browser.vcproj b/chrome/browser/browser.vcproj
index cf27ee4..545c435 100644
--- a/chrome/browser/browser.vcproj
+++ b/chrome/browser/browser.vcproj
@@ -650,15 +650,15 @@
>
</File>
<File
- RelativePath=".\app_modal_dialog_win.cc"
+ RelativePath=".\app_modal_dialog_queue.cc"
>
</File>
<File
- RelativePath=".\app_modal_dialog_queue.cc"
+ RelativePath=".\app_modal_dialog_queue.h"
>
</File>
<File
- RelativePath=".\app_modal_dialog_queue.h"
+ RelativePath=".\app_modal_dialog_win.cc"
>
</File>
<File
@@ -1422,11 +1422,11 @@
Name="Password Manager"
>
<File
- RelativePath=".\password_manager\encryptor_win.cc"
+ RelativePath=".\password_manager\encryptor.h"
>
</File>
<File
- RelativePath=".\password_manager\encryptor.h"
+ RelativePath=".\password_manager\encryptor_win.cc"
>
</File>
<File
@@ -2262,6 +2262,14 @@
>
</File>
<File
+ RelativePath=".\tab_contents\render_view_host_delegate_helper.cc"
+ >
+ </File>
+ <File
+ RelativePath=".\tab_contents\render_view_host_delegate_helper.h"
+ >
+ </File>
+ <File
RelativePath=".\tab_contents\render_view_host_manager.cc"
>
</File>
diff --git a/chrome/browser/extensions/extension_process_manager.cc b/chrome/browser/extensions/extension_process_manager.cc
index 245450c..e9d7bc9 100755
--- a/chrome/browser/extensions/extension_process_manager.cc
+++ b/chrome/browser/extensions/extension_process_manager.cc
@@ -5,6 +5,7 @@
#include "chrome/browser/extensions/extension_process_manager.h"
#include "base/singleton.h"
+#include "chrome/browser/browser.h"
#include "chrome/browser/extensions/extension_view.h"
#include "chrome/browser/tab_contents/site_instance.h"
@@ -21,8 +22,10 @@ ExtensionProcessManager::~ExtensionProcessManager() {
ExtensionView* ExtensionProcessManager::CreateView(Extension* extension,
const GURL& url,
- Profile* profile) {
- return new ExtensionView(extension, url, GetSiteInstanceForURL(url, profile));
+ Browser* browser) {
+ return new ExtensionView(extension, url,
+ GetSiteInstanceForURL(url, browser->profile()),
+ browser);
}
SiteInstance* ExtensionProcessManager::GetSiteInstanceForURL(
diff --git a/chrome/browser/extensions/extension_process_manager.h b/chrome/browser/extensions/extension_process_manager.h
index 0d4048b..fdbff8a 100755
--- a/chrome/browser/extensions/extension_process_manager.h
+++ b/chrome/browser/extensions/extension_process_manager.h
@@ -9,6 +9,7 @@
#include <map>
+class Browser;
class BrowsingInstance;
class Extension;
class ExtensionView;
@@ -36,7 +37,7 @@ class ExtensionProcessManager {
// (and therefore process) based on the URL and profile.
ExtensionView* CreateView(Extension* extension,
const GURL& url,
- Profile* profile);
+ Browser* browser);
// Returns the SiteInstance that the given URL belongs to in this profile.
SiteInstance* GetSiteInstanceForURL(const GURL& url, Profile* profile);
diff --git a/chrome/browser/extensions/extension_view.cc b/chrome/browser/extensions/extension_view.cc
index 969a046..4b3104d 100755
--- a/chrome/browser/extensions/extension_view.cc
+++ b/chrome/browser/extensions/extension_view.cc
@@ -4,21 +4,37 @@
#include "chrome/browser/extensions/extension_view.h"
+#include "base/command_line.h"
+#include "chrome/browser/browser.h"
+#include "chrome/browser/character_encoding.h"
#include "chrome/browser/extensions/extension.h"
#include "chrome/browser/extensions/extension_message_service.h"
+#include "chrome/browser/jsmessage_box_handler.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/renderer_host/render_view_host.h"
#include "chrome/browser/renderer_host/render_process_host.h"
+#include "chrome/browser/renderer_host/render_widget_host.h"
+#include "chrome/browser/renderer_host/render_widget_host_view.h"
+#include "chrome/browser/tab_contents/site_instance.h"
+#include "chrome/browser/tab_contents/web_contents.h"
+#include "chrome/browser/tab_contents/web_contents_view.h"
+#include "chrome/common/chrome_switches.h"
+#include "chrome/common/pref_names.h"
+#include "chrome/common/pref_service.h"
#include "chrome/common/resource_bundle.h"
#include "grit/browser_resources.h"
#include "grit/generated_resources.h"
+#include "webkit/glue/context_menu.h"
+
ExtensionView::ExtensionView(Extension* extension,
const GURL& url,
- SiteInstance* instance)
+ SiteInstance* instance,
+ Browser* browser)
: HWNDHtmlView(url, this, false, instance),
- extension_(extension) {
+ extension_(extension),
+ browser_(browser) {
// Set the width initially to 0, so that the WebCore::Document can
// correctly compute the minPrefWidth which is returned in
// DidContentsChangeSize()
@@ -64,8 +80,9 @@ void ExtensionView::RenderViewCreated(RenderViewHost* rvh) {
}
WebPreferences ExtensionView::GetWebkitPrefs() {
- // TODO(mpcomplete): return some reasonable prefs.
- return WebPreferences();
+ PrefService* prefs = render_view_host()->process()->profile()->GetPrefs();
+ bool isDomUI = true;
+ return RenderViewHostDelegateHelper::GetWebkitPrefs(prefs, isDomUI);
}
void ExtensionView::RunJavaScriptMessage(
@@ -88,3 +105,64 @@ void ExtensionView::DidStartLoading(RenderViewHost* render_view_host,
IDR_EXTENSIONS_TOOLSTRIP_CSS));
render_view_host->InsertCSSInWebFrame(L"", toolstrip_css.as_string());
}
+
+RenderViewHostDelegate::View* ExtensionView::GetViewDelegate() const {
+ // TODO(erikkay) this is unfortunate. The interface declares that this method
+ // must be const (no good reason for it as far as I can tell) which means you
+ // can't return self without doing this const_cast. Either we need to change
+ // the interface, or we need to split out the view delegate into another
+ // object (which is how WebContents works).
+ return const_cast<ExtensionView*>(this);
+}
+
+void ExtensionView::CreateNewWindow(int route_id,
+ base::WaitableEvent* modal_dialog_event) {
+ delegate_view_helper_.CreateNewWindow(route_id, modal_dialog_event,
+ browser_->profile(), site_instance());
+}
+
+void ExtensionView::CreateNewWidget(int route_id, bool activatable) {
+ delegate_view_helper_.CreateNewWidget(route_id, activatable,
+ site_instance()->GetProcess());
+}
+
+void ExtensionView::ShowCreatedWindow(int route_id,
+ WindowOpenDisposition disposition,
+ const gfx::Rect& initial_pos,
+ bool user_gesture) {
+ WebContents* contents = delegate_view_helper_.GetCreatedWindow(route_id);
+ if (contents) {
+ // TODO(erikkay) is it safe to pass in NULL as source?
+ browser_->AddNewContents(NULL, contents, disposition, initial_pos,
+ user_gesture);
+ }
+}
+
+void ExtensionView::ShowCreatedWidget(int route_id,
+ const gfx::Rect& initial_pos) {
+ RenderWidgetHostView* widget_host_view =
+ delegate_view_helper_.GetCreatedWidget(route_id);
+ browser_->RenderWidgetShowing();
+ // TODO(erikkay): These two lines could be refactored with WebContentsView.
+ widget_host_view->InitAsPopup(render_view_host()->view(),
+ initial_pos);
+ widget_host_view->GetRenderWidgetHost()->Init();
+}
+
+void ExtensionView::ShowContextMenu(const ContextMenuParams& params) {
+ // TODO(erikkay) - This is a temporary hack. Show a menu here instead.
+ render_view_host()->InspectElementAt(params.x, params.y);
+}
+
+void ExtensionView::StartDragging(const WebDropData& drop_data) {
+}
+
+void ExtensionView::UpdateDragCursor(bool is_drop_target) {
+}
+
+void ExtensionView::TakeFocus(bool reverse) {
+}
+
+void ExtensionView::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
+}
+
diff --git a/chrome/browser/extensions/extension_view.h b/chrome/browser/extensions/extension_view.h
index 09c7788..7c11371 100755
--- a/chrome/browser/extensions/extension_view.h
+++ b/chrome/browser/extensions/extension_view.h
@@ -6,6 +6,7 @@
#define CHROME_BROWSER_EXTENSIONS_EXTENSION_VIEW_H_
#include "chrome/browser/renderer_host/render_view_host_delegate.h"
+#include "chrome/browser/tab_contents/render_view_host_delegate_helper.h"
// TODO(port): Port these files.
#if defined(OS_WIN)
@@ -14,7 +15,11 @@
#include "chrome/common/temp_scaffolding_stubs.h"
#endif
+class Browser;
class Extension;
+class RenderWidgetHost;
+class RenderWidgetHostView;
+class WebContents;
struct WebPreferences;
// This class is the browser component of an extension component's RenderView.
@@ -22,9 +27,13 @@ struct WebPreferences;
// priviliges available to extensions. The view may be drawn to the screen or
// hidden.
class ExtensionView : public HWNDHtmlView,
- public RenderViewHostDelegate {
+ public RenderViewHostDelegate,
+ public RenderViewHostDelegate::View {
public:
- ExtensionView(Extension* extension, const GURL& url, SiteInstance* instance);
+ ExtensionView(Extension* extension,
+ const GURL& url,
+ SiteInstance* instance,
+ Browser* browser);
// HWNDHtmlView
virtual void CreatingRenderer();
@@ -46,12 +55,35 @@ class ExtensionView : public HWNDHtmlView,
bool* did_suppress_message);
virtual void DidStartLoading(RenderViewHost* render_view_host,
int32 page_id);
+ virtual RenderViewHostDelegate::View* GetViewDelegate() const;
+
+ // RenderViewHostDelegate::View
+ virtual void CreateNewWindow(int route_id,
+ base::WaitableEvent* modal_dialog_event);
+ virtual void CreateNewWidget(int route_id, bool activatable);
+ virtual void ShowCreatedWindow(int route_id,
+ WindowOpenDisposition disposition,
+ const gfx::Rect& initial_pos,
+ bool user_gesture);
+ virtual void ShowCreatedWidget(int route_id,
+ const gfx::Rect& initial_pos);
+ virtual void ShowContextMenu(const ContextMenuParams& params);
+ virtual void StartDragging(const WebDropData& drop_data);
+ virtual void UpdateDragCursor(bool is_drop_target);
+ virtual void TakeFocus(bool reverse);
+ virtual void HandleKeyboardEvent(const NativeWebKeyboardEvent& event);
Extension* extension() { return extension_; }
private:
// The extension that we're hosting in this view.
Extension* extension_;
+ // The browser window that this view is in.
+ Browser* browser_;
+
+ // Common implementations of some RenderViewHostDelegate::View methods.
+ RenderViewHostDelegateViewHelper delegate_view_helper_;
+
DISALLOW_COPY_AND_ASSIGN(ExtensionView);
};
diff --git a/chrome/browser/extensions/extension_view_unittest.cc b/chrome/browser/extensions/extension_view_unittest.cc
index d3d52bf..5784b8a 100755
--- a/chrome/browser/extensions/extension_view_unittest.cc
+++ b/chrome/browser/extensions/extension_view_unittest.cc
@@ -31,8 +31,8 @@ const char* kExtensionId = "00123456789abcdef0123456789abcdef0123456";
class MockExtensionView : public ExtensionView {
public:
MockExtensionView(Extension* extension, const GURL& url,
- SiteInstance* instance)
- : ExtensionView(extension, url, instance), got_message_(false) {
+ SiteInstance* instance, Browser* browser)
+ : ExtensionView(extension, url, instance, browser), got_message_(false) {
InitHidden();
MessageLoop::current()->PostDelayedTask(FROM_HERE,
new MessageLoop::QuitTask, kAlertTimeoutMs);
@@ -93,6 +93,7 @@ IN_PROC_BROWSER_TEST_F(ExtensionViewTest, Index) {
// Start the extension process and wait for it to show a javascript alert.
MockExtensionView view(
extension, url, ExtensionProcessManager::GetInstance()->
- GetSiteInstanceForURL(url, browser()->profile()));
+ GetSiteInstanceForURL(url, browser()->profile()),
+ NULL); // TODO(erikkay): do we need to get a Browser here?
EXPECT_TRUE(view.got_message());
}
diff --git a/chrome/browser/tab_contents/render_view_host_delegate_helper.cc b/chrome/browser/tab_contents/render_view_host_delegate_helper.cc
new file mode 100644
index 0000000..9846a77
--- /dev/null
+++ b/chrome/browser/tab_contents/render_view_host_delegate_helper.cc
@@ -0,0 +1,196 @@
+// Copyright (c) 2009 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 "render_view_host_delegate_helper.h"
+
+#include "base/command_line.h"
+#include "chrome/browser/browser.h"
+#include "chrome/browser/character_encoding.h"
+#include "chrome/browser/profile.h"
+#include "chrome/browser/renderer_host/render_view_host.h"
+#include "chrome/browser/renderer_host/render_process_host.h"
+#include "chrome/browser/renderer_host/render_widget_host.h"
+#include "chrome/browser/renderer_host/render_widget_host_view.h"
+#include "chrome/browser/tab_contents/site_instance.h"
+#include "chrome/browser/tab_contents/web_contents.h"
+#include "chrome/browser/tab_contents/web_contents_view.h"
+#include "chrome/common/chrome_switches.h"
+#include "chrome/common/pref_names.h"
+#include "chrome/common/pref_service.h"
+
+void RenderViewHostDelegateViewHelper::CreateNewWindow(int route_id,
+ base::WaitableEvent* modal_dialog_event, Profile* profile,
+ SiteInstance* site) {
+ // Create the new web contents. This will automatically create the new
+ // WebContentsView. In the future, we may want to create the view separately.
+ WebContents* new_contents =
+ new WebContents(profile,
+ site,
+ route_id,
+ modal_dialog_event);
+ new_contents->SetupController(profile);
+ WebContentsView* new_view = new_contents->view();
+
+ // TODO(brettw) it seems bogus that we have to call this function on the
+ // newly created object and give it one of its own member variables.
+ new_view->CreateViewForWidget(new_contents->render_view_host());
+
+ // Save the created window associated with the route so we can show it later.
+ pending_contents_[route_id] = new_contents;
+}
+
+RenderWidgetHostView* RenderViewHostDelegateViewHelper::CreateNewWidget(
+ int route_id, bool activatable, RenderProcessHost* process) {
+ RenderWidgetHost* widget_host =
+ new RenderWidgetHost(process, route_id);
+ RenderWidgetHostView* widget_view =
+ RenderWidgetHostView::CreateViewForWidget(widget_host);
+ widget_view->set_activatable(activatable);
+ // Save the created widget associated with the route so we can show it later.
+ pending_widget_views_[route_id] = widget_view;
+ return widget_view;
+}
+
+WebContents* RenderViewHostDelegateViewHelper::GetCreatedWindow(int route_id) {
+ PendingContents::iterator iter = pending_contents_.find(route_id);
+ if (iter == pending_contents_.end()) {
+ DCHECK(false);
+ return NULL;
+ }
+
+ WebContents* new_web_contents = iter->second;
+ pending_contents_.erase(route_id);
+
+ if (!new_web_contents->render_view_host()->view() ||
+ !new_web_contents->process()->channel()) {
+ // The view has gone away or the renderer crashed. Nothing to do.
+ return NULL;
+ }
+
+ // TODO(brettw) this seems bogus to reach into here and initialize the host.
+ new_web_contents->render_view_host()->Init();
+
+ return new_web_contents;
+}
+
+RenderWidgetHostView* RenderViewHostDelegateViewHelper::GetCreatedWidget(
+ int route_id) {
+ PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
+ if (iter == pending_widget_views_.end()) {
+ DCHECK(false);
+ return NULL;
+ }
+
+ RenderWidgetHostView* widget_host_view = iter->second;
+ pending_widget_views_.erase(route_id);
+
+ RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
+ if (!widget_host->process()->channel()) {
+ // The view has gone away or the renderer crashed. Nothing to do.
+ return NULL;
+ }
+
+ return widget_host_view;
+}
+
+void RenderViewHostDelegateViewHelper::RenderWidgetHostDestroyed(
+ RenderWidgetHost* host) {
+ for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
+ i != pending_widget_views_.end(); ++i) {
+ if (host->view() == i->second) {
+ pending_widget_views_.erase(i);
+ return;
+ }
+ }
+}
+
+// static
+WebPreferences RenderViewHostDelegateHelper::GetWebkitPrefs(
+ PrefService* prefs, bool is_dom_ui) {
+
+ WebPreferences web_prefs;
+
+ web_prefs.fixed_font_family =
+ prefs->GetString(prefs::kWebKitFixedFontFamily);
+ web_prefs.serif_font_family =
+ prefs->GetString(prefs::kWebKitSerifFontFamily);
+ web_prefs.sans_serif_font_family =
+ prefs->GetString(prefs::kWebKitSansSerifFontFamily);
+ if (prefs->GetBoolean(prefs::kWebKitStandardFontIsSerif))
+ web_prefs.standard_font_family = web_prefs.serif_font_family;
+ else
+ web_prefs.standard_font_family = web_prefs.sans_serif_font_family;
+ web_prefs.cursive_font_family =
+ prefs->GetString(prefs::kWebKitCursiveFontFamily);
+ web_prefs.fantasy_font_family =
+ prefs->GetString(prefs::kWebKitFantasyFontFamily);
+
+ web_prefs.default_font_size =
+ prefs->GetInteger(prefs::kWebKitDefaultFontSize);
+ web_prefs.default_fixed_font_size =
+ prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
+ web_prefs.minimum_font_size =
+ prefs->GetInteger(prefs::kWebKitMinimumFontSize);
+ web_prefs.minimum_logical_font_size =
+ prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
+
+ web_prefs.default_encoding = prefs->GetString(prefs::kDefaultCharset);
+
+ web_prefs.javascript_can_open_windows_automatically =
+ prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
+ web_prefs.dom_paste_enabled =
+ prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
+ web_prefs.shrinks_standalone_images_to_fit =
+ prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
+
+ { // Command line switches are used for preferences with no user interface.
+ const CommandLine& command_line = *CommandLine::ForCurrentProcess();
+ web_prefs.developer_extras_enabled =
+ !command_line.HasSwitch(switches::kDisableDevTools) &&
+ prefs->GetBoolean(prefs::kWebKitDeveloperExtrasEnabled);
+ web_prefs.javascript_enabled =
+ !command_line.HasSwitch(switches::kDisableJavaScript) &&
+ prefs->GetBoolean(prefs::kWebKitJavascriptEnabled);
+ web_prefs.web_security_enabled =
+ !command_line.HasSwitch(switches::kDisableWebSecurity) &&
+ prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled);
+ web_prefs.plugins_enabled =
+ !command_line.HasSwitch(switches::kDisablePlugins) &&
+ prefs->GetBoolean(prefs::kWebKitPluginsEnabled);
+ web_prefs.java_enabled =
+ !command_line.HasSwitch(switches::kDisableJava) &&
+ prefs->GetBoolean(prefs::kWebKitJavaEnabled);
+ web_prefs.loads_images_automatically =
+ !command_line.HasSwitch(switches::kDisableImages) &&
+ prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
+ web_prefs.uses_page_cache =
+ command_line.HasSwitch(switches::kEnableFastback);
+ }
+
+ web_prefs.uses_universal_detector =
+ prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
+ web_prefs.text_areas_are_resizable =
+ prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
+
+ // User CSS is currently disabled because it crashes chrome. See
+ // webkit/glue/webpreferences.h for more details.
+
+ // Make sure we will set the default_encoding with canonical encoding name.
+ web_prefs.default_encoding =
+ CharacterEncoding::GetCanonicalEncodingNameByAliasName(
+ web_prefs.default_encoding);
+ if (web_prefs.default_encoding.empty()) {
+ prefs->ClearPref(prefs::kDefaultCharset);
+ web_prefs.default_encoding = prefs->GetString(
+ prefs::kDefaultCharset);
+ }
+ DCHECK(!web_prefs.default_encoding.empty());
+
+ if (is_dom_ui) {
+ web_prefs.loads_images_automatically = true;
+ web_prefs.javascript_enabled = true;
+ }
+
+ return web_prefs;
+}
diff --git a/chrome/browser/tab_contents/render_view_host_delegate_helper.h b/chrome/browser/tab_contents/render_view_host_delegate_helper.h
new file mode 100644
index 0000000..2263829
--- /dev/null
+++ b/chrome/browser/tab_contents/render_view_host_delegate_helper.h
@@ -0,0 +1,68 @@
+// Copyright (c) 2009 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.
+
+#ifndef CHROME_BROWSER_TAB_CONTENTS_RENDER_VIEW_HOST_DELEGATE_HELPER_H_
+#define CHROME_BROWSER_TAB_CONTENTS_RENDER_VIEW_HOST_DELEGATE_HELPER_H_
+
+#include <map>
+
+#include "base/basictypes.h"
+#include "base/gfx/rect.h"
+#include "base/waitable_event.h"
+#include "webkit/glue/webpreferences.h"
+#include "webkit/glue/window_open_disposition.h"
+
+class Browser;
+class PrefService;
+class Profile;
+class RenderProcessHost;
+class RenderViewHost;
+class RenderWidgetHost;
+class RenderWidgetHostView;
+class SiteInstance;
+class WebContents;
+
+// Provides helper methods that provide common implementations of some
+// RenderViewHostDelegate::View methods.
+class RenderViewHostDelegateViewHelper {
+ public:
+ RenderViewHostDelegateViewHelper() {}
+
+ virtual void CreateNewWindow(int route_id,
+ base::WaitableEvent* modal_dialog_event,
+ Profile* profile, SiteInstance* site);
+ virtual RenderWidgetHostView* CreateNewWidget(int route_id, bool activatable,
+ RenderProcessHost* process);
+ virtual WebContents* GetCreatedWindow(int route_id);
+ virtual RenderWidgetHostView* GetCreatedWidget(int route_id);
+ void RenderWidgetHostDestroyed(RenderWidgetHost* host);
+
+ private:
+ // Tracks created WebContents objects that have not been shown yet. They are
+ // identified by the route ID passed to CreateNewWindow.
+ typedef std::map<int, WebContents*> PendingContents;
+ PendingContents pending_contents_;
+
+ // These maps hold on to the widgets that we created on behalf of the
+ // renderer that haven't shown yet.
+ typedef std::map<int, RenderWidgetHostView*> PendingWidgetViews;
+ PendingWidgetViews pending_widget_views_;
+
+ DISALLOW_COPY_AND_ASSIGN(RenderViewHostDelegateViewHelper);
+};
+
+
+// Provides helper methods that provide common implementations of some
+// RenderViewHostDelegate methods.
+class RenderViewHostDelegateHelper {
+ public:
+ static WebPreferences GetWebkitPrefs(PrefService* prefs, bool is_dom_ui);
+
+ private:
+ RenderViewHostDelegateHelper();
+
+ DISALLOW_COPY_AND_ASSIGN(RenderViewHostDelegateHelper);
+};
+
+#endif // CHROME_BROWSER_TAB_CONTENTS_RENDER_VIEW_HOST_DELEGATE_HELPER_H_
diff --git a/chrome/browser/tab_contents/web_contents.cc b/chrome/browser/tab_contents/web_contents.cc
index b58d7b3..b91c693 100644
--- a/chrome/browser/tab_contents/web_contents.cc
+++ b/chrome/browser/tab_contents/web_contents.cc
@@ -1335,94 +1335,9 @@ GURL WebContents::GetAlternateErrorPageURL() const {
}
WebPreferences WebContents::GetWebkitPrefs() {
- // Initialize web_preferences_ to chrome defaults.
- WebPreferences web_prefs;
- PrefService* prefs = profile()->GetPrefs();
-
- web_prefs.fixed_font_family =
- prefs->GetString(prefs::kWebKitFixedFontFamily);
- web_prefs.serif_font_family =
- prefs->GetString(prefs::kWebKitSerifFontFamily);
- web_prefs.sans_serif_font_family =
- prefs->GetString(prefs::kWebKitSansSerifFontFamily);
- if (prefs->GetBoolean(prefs::kWebKitStandardFontIsSerif))
- web_prefs.standard_font_family = web_prefs.serif_font_family;
- else
- web_prefs.standard_font_family = web_prefs.sans_serif_font_family;
- web_prefs.cursive_font_family =
- prefs->GetString(prefs::kWebKitCursiveFontFamily);
- web_prefs.fantasy_font_family =
- prefs->GetString(prefs::kWebKitFantasyFontFamily);
-
- web_prefs.default_font_size =
- prefs->GetInteger(prefs::kWebKitDefaultFontSize);
- web_prefs.default_fixed_font_size =
- prefs->GetInteger(prefs::kWebKitDefaultFixedFontSize);
- web_prefs.minimum_font_size =
- prefs->GetInteger(prefs::kWebKitMinimumFontSize);
- web_prefs.minimum_logical_font_size =
- prefs->GetInteger(prefs::kWebKitMinimumLogicalFontSize);
-
- web_prefs.default_encoding = prefs->GetString(prefs::kDefaultCharset);
-
- web_prefs.javascript_can_open_windows_automatically =
- prefs->GetBoolean(prefs::kWebKitJavascriptCanOpenWindowsAutomatically);
- web_prefs.dom_paste_enabled =
- prefs->GetBoolean(prefs::kWebKitDomPasteEnabled);
- web_prefs.shrinks_standalone_images_to_fit =
- prefs->GetBoolean(prefs::kWebKitShrinksStandaloneImagesToFit);
-
- { // Command line switches are used for preferences with no user interface.
- const CommandLine& command_line = *CommandLine::ForCurrentProcess();
- web_prefs.developer_extras_enabled =
- !command_line.HasSwitch(switches::kDisableDevTools) &&
- prefs->GetBoolean(prefs::kWebKitDeveloperExtrasEnabled);
- web_prefs.javascript_enabled =
- !command_line.HasSwitch(switches::kDisableJavaScript) &&
- prefs->GetBoolean(prefs::kWebKitJavascriptEnabled);
- web_prefs.web_security_enabled =
- !command_line.HasSwitch(switches::kDisableWebSecurity) &&
- prefs->GetBoolean(prefs::kWebKitWebSecurityEnabled);
- web_prefs.plugins_enabled =
- !command_line.HasSwitch(switches::kDisablePlugins) &&
- prefs->GetBoolean(prefs::kWebKitPluginsEnabled);
- web_prefs.java_enabled =
- !command_line.HasSwitch(switches::kDisableJava) &&
- prefs->GetBoolean(prefs::kWebKitJavaEnabled);
- web_prefs.loads_images_automatically =
- !command_line.HasSwitch(switches::kDisableImages) &&
- prefs->GetBoolean(prefs::kWebKitLoadsImagesAutomatically);
- web_prefs.uses_page_cache =
- command_line.HasSwitch(switches::kEnableFastback);
- }
-
- web_prefs.uses_universal_detector =
- prefs->GetBoolean(prefs::kWebKitUsesUniversalDetector);
- web_prefs.text_areas_are_resizable =
- prefs->GetBoolean(prefs::kWebKitTextAreasAreResizable);
-
- // User CSS is currently disabled because it crashes chrome. See
- // webkit/glue/webpreferences.h for more details.
-
- // Make sure we will set the default_encoding with canonical encoding name.
- web_prefs.default_encoding =
- CharacterEncoding::GetCanonicalEncodingNameByAliasName(
- web_prefs.default_encoding);
- if (web_prefs.default_encoding.empty()) {
- prefs->ClearPref(prefs::kDefaultCharset);
- web_prefs.default_encoding = prefs->GetString(
- prefs::kDefaultCharset);
- }
- DCHECK(!web_prefs.default_encoding.empty());
-
- // Override some prefs when we're a DOM UI, or the pages won't work. This is
- // called during setup, so we will always use the pending one.
- if (render_manager_.pending_dom_ui()) {
- web_prefs.loads_images_automatically = true;
- web_prefs.javascript_enabled = true;
- }
-
- return web_prefs;
+ PrefService* prefs = render_view_host()->process()->profile()->GetPrefs();
+ bool isDomUI = false;
+ return RenderViewHostDelegateHelper::GetWebkitPrefs(prefs, isDomUI);
}
void WebContents::OnMissingPluginStatus(int status) {
diff --git a/chrome/browser/tab_contents/web_contents_view.cc b/chrome/browser/tab_contents/web_contents_view.cc
index 294b3ca..2a7a3d9 100644
--- a/chrome/browser/tab_contents/web_contents_view.cc
+++ b/chrome/browser/tab_contents/web_contents_view.cc
@@ -10,109 +10,59 @@
#include "chrome/browser/tab_contents/tab_contents_delegate.h"
#include "chrome/browser/tab_contents/web_contents.h"
-WebContentsView::WebContentsView(WebContents* web_contents)
+WebContentsView::WebContentsView(WebContents* web_contents)
: web_contents_(web_contents) {
}
+void WebContentsView::CreateView() {
+}
+
void WebContentsView::RenderWidgetHostDestroyed(RenderWidgetHost* host) {
- for (PendingWidgetViews::iterator i = pending_widget_views_.begin();
- i != pending_widget_views_.end(); ++i) {
- if (host->view() == i->second) {
- pending_widget_views_.erase(i);
- return;
- }
- }
+ delegate_view_helper_.RenderWidgetHostDestroyed(host);
}
void WebContentsView::CreateNewWindow(int route_id,
base::WaitableEvent* modal_dialog_event) {
- // Create the new web contents. This will automatically create the new
- // WebContentsView. In the future, we may want to create the view separately.
- WebContents* new_contents =
- new WebContents(web_contents()->profile(),
- web_contents()->GetSiteInstance(),
- route_id,
- modal_dialog_event);
- new_contents->SetupController(web_contents()->profile());
- WebContentsView* new_view = new_contents->view();
-
- // TODO(brettw) it seems bogus that we have to call this function on the
- // newly created object and give it one of its own member variables.
- new_view->CreateViewForWidget(new_contents->render_view_host());
-
- // Save the created window associated with the route so we can show it later.
- pending_contents_[route_id] = new_contents;
+ delegate_view_helper_.CreateNewWindow(route_id, modal_dialog_event,
+ web_contents_->profile(),
+ web_contents_->GetSiteInstance());
}
void WebContentsView::CreateNewWidget(int route_id, bool activatable) {
- // Save the created widget associated with the route so we can show it later.
- pending_widget_views_[route_id] = CreateNewWidgetInternal(route_id,
- activatable);
+ CreateNewWidgetInternal(route_id, activatable);
}
void WebContentsView::ShowCreatedWindow(int route_id,
WindowOpenDisposition disposition,
const gfx::Rect& initial_pos,
bool user_gesture) {
- PendingContents::iterator iter = pending_contents_.find(route_id);
- if (iter == pending_contents_.end()) {
- DCHECK(false);
- return;
+ WebContents* contents = delegate_view_helper_.GetCreatedWindow(route_id);
+ if (contents) {
+ web_contents()->AddNewContents(contents, disposition, initial_pos,
+ user_gesture);
}
-
- WebContents* new_web_contents = iter->second;
- pending_contents_.erase(route_id);
-
- if (!new_web_contents->render_widget_host_view() ||
- !new_web_contents->process()->channel()) {
- // The view has gone away or the renderer crashed. Nothing to do.
- return;
- }
-
- // TODO(brettw) this seems bogus to reach into here and initialize the host.
- new_web_contents->render_view_host()->Init();
- web_contents()->AddNewContents(new_web_contents, disposition, initial_pos,
- user_gesture);
}
void WebContentsView::ShowCreatedWidget(int route_id,
const gfx::Rect& initial_pos) {
- PendingWidgetViews::iterator iter = pending_widget_views_.find(route_id);
- if (iter == pending_widget_views_.end()) {
- DCHECK(false);
- return;
- }
-
- RenderWidgetHostView* widget_host_view = iter->second;
- pending_widget_views_.erase(route_id);
-
+ RenderWidgetHostView* widget_host_view =
+ delegate_view_helper_.GetCreatedWidget(route_id);
ShowCreatedWidgetInternal(widget_host_view, initial_pos);
}
RenderWidgetHostView* WebContentsView::CreateNewWidgetInternal(
- int route_id,
- bool activatable) {
- RenderWidgetHost* widget_host =
- new RenderWidgetHost(web_contents_->process(), route_id);
- RenderWidgetHostView* widget_view =
- RenderWidgetHostView::CreateViewForWidget(widget_host);
- widget_view->set_activatable(activatable);
-
- return widget_view;
+ int route_id, bool activatable) {
+ return delegate_view_helper_.CreateNewWidget(route_id, activatable,
+ web_contents()->render_view_host()->process());
}
void WebContentsView::ShowCreatedWidgetInternal(
- RenderWidgetHostView* widget_host_view,
- const gfx::Rect& initial_pos) {
- RenderWidgetHost* widget_host = widget_host_view->GetRenderWidgetHost();
- if (!widget_host->process()->channel()) {
- // The view has gone away or the renderer crashed. Nothing to do.
- return;
- }
-
+ RenderWidgetHostView* widget_host_view, const gfx::Rect& initial_pos) {
if (web_contents_->delegate())
web_contents_->delegate()->RenderWidgetShowing();
- widget_host_view->InitAsPopup(
- web_contents_->render_widget_host_view(), initial_pos);
- widget_host->Init();
+
+ widget_host_view->InitAsPopup(web_contents_->render_widget_host_view(),
+ initial_pos);
+ widget_host_view->GetRenderWidgetHost()->Init();
}
+
diff --git a/chrome/browser/tab_contents/web_contents_view.h b/chrome/browser/tab_contents/web_contents_view.h
index a63c84c..2efd6f2 100644
--- a/chrome/browser/tab_contents/web_contents_view.h
+++ b/chrome/browser/tab_contents/web_contents_view.h
@@ -13,6 +13,7 @@
#include "base/gfx/rect.h"
#include "base/gfx/size.h"
#include "chrome/browser/renderer_host/render_view_host_delegate.h"
+#include "chrome/browser/tab_contents/render_view_host_delegate_helper.h"
class Browser;
class RenderViewHost;
@@ -137,6 +138,9 @@ class WebContentsView : public RenderViewHostDelegate::View {
virtual void ShowCreatedWidgetInternal(RenderWidgetHostView* widget_host_view,
const gfx::Rect& initial_pos);
+ // Common implementations of some RenderViewHostDelegate::View methods.
+ RenderViewHostDelegateViewHelper delegate_view_helper_;
+
private:
// We implement these functions on RenderViewHostDelegate::View directly and
// do some book-keeping associated with the request. The request is then
diff --git a/chrome/browser/views/bookmark_bar_view.cc b/chrome/browser/views/bookmark_bar_view.cc
index 2c41482..62dd928 100644
--- a/chrome/browser/views/bookmark_bar_view.cc
+++ b/chrome/browser/views/bookmark_bar_view.cc
@@ -300,9 +300,9 @@ class ExtensionToolstrip : public views::View {
public:
static const int kPadding = 2;
- ExtensionToolstrip(Extension* extension, const GURL& url, Profile* profile)
+ ExtensionToolstrip(Extension* extension, const GURL& url, Browser* browser)
: view_(ExtensionProcessManager::GetInstance()->CreateView(
- extension, url, profile)) {
+ extension, url, browser)) {
AddChildView(view_);
set_border(views::Border::CreateEmptyBorder(
kPadding, kPadding, kPadding, kPadding));
@@ -1378,7 +1378,7 @@ bool BookmarkBarView::AddExtensionToolstrips(const ExtensionList* extensions) {
ExtensionToolstrip* view =
new ExtensionToolstrip(*extension,
(*extension)->GetResourceURL(*toolstrip),
- profile_);
+ browser_);
int index = GetBookmarkButtonCount() + num_extension_toolstrips_;
AddChildView(index, view);
added_toolstrip = true;
diff --git a/chrome/browser/views/hwnd_html_view.h b/chrome/browser/views/hwnd_html_view.h
index 9a55496..3176551 100644
--- a/chrome/browser/views/hwnd_html_view.h
+++ b/chrome/browser/views/hwnd_html_view.h
@@ -35,6 +35,8 @@ class HWNDHtmlView : public views::HWNDView {
// opportunity to do some setup.
virtual void CreatingRenderer() {}
+ SiteInstance* site_instance() { return site_instance_; }
+
private:
// Initialize the view, parented to |parent|, and show it.
void Init(HWND parent);