Index: chrome/browser/extensions/extension_host.cc |
=================================================================== |
--- chrome/browser/extensions/extension_host.cc (revision 14092) |
+++ chrome/browser/extensions/extension_host.cc (working copy) |
@@ -2,14 +2,13 @@ |
// Use of this source code is governed by a BSD-style license that can be |
// found in the LICENSE file. |
-#include "chrome/browser/extensions/extension_view.h" |
+#include "chrome/browser/extensions/extension_host.h" |
-#include "base/command_line.h" |
#include "chrome/browser/browser.h" |
-#include "chrome/browser/character_encoding.h" |
+#include "chrome/browser/browser_list.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/extensions/extension_view.h" |
#include "chrome/browser/profile.h" |
#include "chrome/browser/renderer_host/render_view_host.h" |
#include "chrome/browser/renderer_host/render_process_host.h" |
@@ -18,7 +17,6 @@ |
#include "chrome/browser/tab_contents/site_instance.h" |
#include "chrome/browser/tab_contents/web_contents.h" |
#include "chrome/browser/tab_contents/tab_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" |
@@ -28,64 +26,46 @@ |
#include "webkit/glue/context_menu.h" |
-ExtensionView::ExtensionView(Extension* extension, |
- const GURL& url, |
- SiteInstance* instance, |
- Browser* browser) |
- : HWNDHtmlView(url, this, false, instance), |
- 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() |
- set_preferred_size(gfx::Size(0, 100)); |
- SetVisible(false); |
+ExtensionHost::ExtensionHost(Extension* extension, SiteInstance* site_instance) |
+ : extension_(extension), view_(NULL), did_stop_loading_(false) { |
+ render_view_host_ = new RenderViewHost( |
+ site_instance, this, MSG_ROUTING_NONE, NULL); |
+ render_view_host_->AllowExtensionBindings(); |
} |
-void ExtensionView::DidStopLoading(RenderViewHost* render_view_host, |
- int32 page_id) { |
- SetVisible(true); |
- render_view_host->WasResized(); |
+ExtensionHost::~ExtensionHost() { |
+ render_view_host_->Shutdown(); // deletes render_view_host |
} |
-void ExtensionView::DidContentsPreferredWidthChange(const int pref_width) { |
- if (pref_width > 0) { |
- // SchedulePaint first because new_width may be smaller and we want |
- // the Parent to paint the vacated space. |
- SchedulePaint(); |
- set_preferred_size(gfx::Size(pref_width, 100)); |
- SizeToPreferredSize(); |
+SiteInstance* ExtensionHost::site_instance() const { |
+ return render_view_host_->site_instance(); |
+} |
- // TODO(rafaelw): This assumes that the extension view is a child of an |
- // ExtensionToolstrip, which is a child of the BookmarkBarView. There should |
- // be a way to do this where the ExtensionView doesn't have to know it's |
- // containment hierarchy. |
- if (GetParent() != NULL && GetParent()->GetParent() != NULL) { |
- GetParent()->GetParent()->Layout(); |
- } |
- |
- SchedulePaint(); |
- render_view_host()->WasResized(); |
- } |
+void ExtensionHost::CreateRenderView(const GURL& url, |
+ RenderWidgetHostView* host_view) { |
+ render_view_host_->set_view(host_view); |
+ render_view_host_->CreateRenderView(); |
+ render_view_host_->NavigateToURL(url); |
} |
-void ExtensionView::CreatingRenderer() { |
- render_view_host()->AllowExtensionBindings(); |
+void ExtensionHost::DidContentsPreferredWidthChange(const int pref_width) { |
+ if (view_) |
+ view_->DidContentsPreferredWidthChange(pref_width); |
} |
-void ExtensionView::RenderViewCreated(RenderViewHost* rvh) { |
+void ExtensionHost::RenderViewCreated(RenderViewHost* rvh) { |
URLRequestContext* context = rvh->process()->profile()->GetRequestContext(); |
ExtensionMessageService::GetInstance(context)->RegisterExtension( |
- extension_->id(), render_view_host()->process()->pid()); |
+ extension_->id(), rvh->process()->pid()); |
} |
-WebPreferences ExtensionView::GetWebkitPrefs() { |
+WebPreferences ExtensionHost::GetWebkitPrefs() { |
PrefService* prefs = render_view_host()->process()->profile()->GetPrefs(); |
- bool isDomUI = true; |
- return RenderViewHostDelegateHelper::GetWebkitPrefs(prefs, isDomUI); |
+ const bool kIsDomUI = true; |
+ return RenderViewHostDelegateHelper::GetWebkitPrefs(prefs, kIsDomUI); |
} |
-void ExtensionView::RunJavaScriptMessage( |
+void ExtensionHost::RunJavaScriptMessage( |
const std::wstring& message, |
const std::wstring& default_prompt, |
const GURL& frame_url, |
@@ -98,71 +78,94 @@ |
render_view_host()->JavaScriptMessageBoxClosed(reply_msg, true, L""); |
} |
-void ExtensionView::DidStartLoading(RenderViewHost* render_view_host, |
- int32 page_id) { |
+void ExtensionHost::DidStartLoading(RenderViewHost* render_view_host) { |
static const StringPiece toolstrip_css( |
ResourceBundle::GetSharedInstance().GetRawDataResource( |
IDR_EXTENSIONS_TOOLSTRIP_CSS)); |
render_view_host->InsertCSSInWebFrame(L"", toolstrip_css.as_string()); |
} |
-RenderViewHostDelegate::View* ExtensionView::GetViewDelegate() const { |
+void ExtensionHost::DidStopLoading(RenderViewHost* render_view_host) { |
+ render_view_host->WasResized(); |
+ did_stop_loading_ = true; |
+ if (view_) |
+ view_->ShowIfCompletelyLoaded(); |
+} |
+ |
+ExtensionFunctionDispatcher* ExtensionHost:: |
+ CreateExtensionFunctionDispatcher(RenderViewHost *render_view_host, |
+ const std::string& extension_id) { |
+ return new ExtensionFunctionDispatcher(render_view_host, GetBrowser(), |
+ extension_id); |
+} |
+ |
+RenderViewHostDelegate::View* ExtensionHost::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); |
+ return const_cast<ExtensionHost*>(this); |
} |
-void ExtensionView::CreateNewWindow(int route_id, |
+void ExtensionHost::CreateNewWindow(int route_id, |
base::WaitableEvent* modal_dialog_event) { |
- delegate_view_helper_.CreateNewWindow(route_id, modal_dialog_event, |
- browser_->profile(), site_instance()); |
+ delegate_view_helper_.CreateNewWindow( |
+ route_id, modal_dialog_event, render_view_host()->process()->profile(), |
+ site_instance()); |
} |
-void ExtensionView::CreateNewWidget(int route_id, bool activatable) { |
+void ExtensionHost::CreateNewWidget(int route_id, bool activatable) { |
delegate_view_helper_.CreateNewWidget(route_id, activatable, |
site_instance()->GetProcess()); |
} |
-void ExtensionView::ShowCreatedWindow(int route_id, |
+void ExtensionHost::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); |
+ GetBrowser()->AddTabContents(contents, disposition, initial_pos, |
+ user_gesture); |
} |
} |
-void ExtensionView::ShowCreatedWidget(int route_id, |
+void ExtensionHost::ShowCreatedWidget(int route_id, |
const gfx::Rect& initial_pos) { |
RenderWidgetHostView* widget_host_view = |
delegate_view_helper_.GetCreatedWidget(route_id); |
- browser_->RenderWidgetShowing(); |
+ GetBrowser()->BrowserRenderWidgetShowing(); |
// TODO(erikkay): These two lines could be refactored with TabContentsView. |
- widget_host_view->InitAsPopup(render_view_host()->view(), |
- initial_pos); |
+ widget_host_view->InitAsPopup(render_view_host()->view(), initial_pos); |
widget_host_view->GetRenderWidgetHost()->Init(); |
} |
-void ExtensionView::ShowContextMenu(const ContextMenuParams& params) { |
+void ExtensionHost::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 ExtensionHost::StartDragging(const WebDropData& drop_data) { |
} |
-void ExtensionView::UpdateDragCursor(bool is_drop_target) { |
+void ExtensionHost::UpdateDragCursor(bool is_drop_target) { |
} |
-void ExtensionView::TakeFocus(bool reverse) { |
+void ExtensionHost::TakeFocus(bool reverse) { |
} |
-void ExtensionView::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { |
+void ExtensionHost::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { |
} |
+Browser* ExtensionHost::GetBrowser() { |
+ if (view_) |
+ return view_->browser(); |
+ Browser* browser = BrowserList::FindBrowserWithProfile( |
+ render_view_host()->process()->profile()); |
+ // TODO(mpcomplete): what this verifies doesn't actually happen yet. |
+ CHECK(browser) << "ExtensionHost running in Profile with no Browser active." |
+ " It should have been deleted."; |
+ return browser; |
+} |