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

Side by Side Diff: chrome/browser/extensions/extension_host.cc

Issue 385061: experimental.popup support for tab-content-viewed extensions (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/extension_host.h" 5 #include "chrome/browser/extensions/extension_host.h"
6 6
7 #include <list> 7 #include <list>
8 8
9 #include "app/l10n_util.h" 9 #include "app/l10n_util.h"
10 #include "app/resource_bundle.h" 10 #include "app/resource_bundle.h"
11 #include "base/message_loop.h" 11 #include "base/message_loop.h"
12 #include "base/singleton.h" 12 #include "base/singleton.h"
13 #include "base/string_util.h" 13 #include "base/string_util.h"
14 #include "chrome/browser/browser.h" 14 #include "chrome/browser/browser.h"
15 #include "chrome/browser/browser_list.h" 15 #include "chrome/browser/browser_list.h"
16 #include "chrome/browser/browser_theme_provider.h" 16 #include "chrome/browser/browser_theme_provider.h"
17 #include "chrome/browser/browsing_instance.h" 17 #include "chrome/browser/browsing_instance.h"
18 #include "chrome/browser/debugger/devtools_manager.h" 18 #include "chrome/browser/debugger/devtools_manager.h"
19 #include "chrome/browser/dom_ui/dom_ui_factory.h" 19 #include "chrome/browser/dom_ui/dom_ui_factory.h"
20 #include "chrome/browser/extensions/extension_message_service.h" 20 #include "chrome/browser/extensions/extension_message_service.h"
21 #include "chrome/browser/extensions/extension_tabs_module.h" 21 #include "chrome/browser/extensions/extension_tabs_module.h"
22 #include "chrome/browser/jsmessage_box_handler.h" 22 #include "chrome/browser/jsmessage_box_handler.h"
23 #include "chrome/browser/extensions/extension_popup_api.h"
24 #include "chrome/browser/profile.h" 23 #include "chrome/browser/profile.h"
25 #include "chrome/browser/renderer_host/render_view_host.h" 24 #include "chrome/browser/renderer_host/render_view_host.h"
26 #include "chrome/browser/renderer_host/render_process_host.h" 25 #include "chrome/browser/renderer_host/render_process_host.h"
27 #include "chrome/browser/renderer_host/render_widget_host.h" 26 #include "chrome/browser/renderer_host/render_widget_host.h"
28 #include "chrome/browser/renderer_host/render_widget_host_view.h" 27 #include "chrome/browser/renderer_host/render_widget_host_view.h"
29 #include "chrome/browser/renderer_host/site_instance.h" 28 #include "chrome/browser/renderer_host/site_instance.h"
30 #include "chrome/browser/tab_contents/tab_contents.h" 29 #include "chrome/browser/tab_contents/tab_contents.h"
31 #include "chrome/browser/tab_contents/tab_contents_view.h" 30 #include "chrome/browser/tab_contents/tab_contents_view.h"
32 #include "chrome/common/bindings_policy.h" 31 #include "chrome/common/bindings_policy.h"
33 #include "chrome/common/extensions/extension.h" 32 #include "chrome/common/extensions/extension.h"
34 #include "chrome/common/notification_service.h" 33 #include "chrome/common/notification_service.h"
35 #include "chrome/common/pref_names.h" 34 #include "chrome/common/pref_names.h"
36 #include "chrome/common/pref_service.h" 35 #include "chrome/common/pref_service.h"
37 #include "chrome/common/view_types.h" 36 #include "chrome/common/view_types.h"
38 #include "chrome/common/render_messages.h" 37 #include "chrome/common/render_messages.h"
39 #include "chrome/common/url_constants.h" 38 #include "chrome/common/url_constants.h"
40 #include "grit/browser_resources.h" 39 #include "grit/browser_resources.h"
41 #include "grit/generated_resources.h" 40 #include "grit/generated_resources.h"
42 #include "webkit/glue/context_menu.h" 41 #include "webkit/glue/context_menu.h"
43 42
44 #if defined(TOOLKIT_VIEWS) 43 #if defined(TOOLKIT_VIEWS)
45 #include "chrome/browser/views/extensions/extension_popup.h"
46 #include "views/widget/widget.h" 44 #include "views/widget/widget.h"
47 #endif 45 #endif
48 46
49 using WebKit::WebDragOperation; 47 using WebKit::WebDragOperation;
50 using WebKit::WebDragOperationsMask; 48 using WebKit::WebDragOperationsMask;
51 49
52 // static 50 // static
53 bool ExtensionHost::enable_dom_automation_ = false; 51 bool ExtensionHost::enable_dom_automation_ = false;
54 52
55 static const char* kToolstripTextColorSubstitution = "$TEXT_COLOR$"; 53 static const char* kToolstripTextColorSubstitution = "$TEXT_COLOR$";
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
114 //////////////// 112 ////////////////
115 // ExtensionHost 113 // ExtensionHost
116 114
117 ExtensionHost::ExtensionHost(Extension* extension, SiteInstance* site_instance, 115 ExtensionHost::ExtensionHost(Extension* extension, SiteInstance* site_instance,
118 const GURL& url, ViewType::Type host_type) 116 const GURL& url, ViewType::Type host_type)
119 : extension_(extension), 117 : extension_(extension),
120 profile_(site_instance->browsing_instance()->profile()), 118 profile_(site_instance->browsing_instance()->profile()),
121 did_stop_loading_(false), 119 did_stop_loading_(false),
122 document_element_available_(false), 120 document_element_available_(false),
123 url_(url), 121 url_(url),
124 #if defined(TOOLKIT_VIEWS)
125 child_popup_(NULL),
126 #endif
127 extension_host_type_(host_type) { 122 extension_host_type_(host_type) {
128 render_view_host_ = new RenderViewHost(site_instance, this, MSG_ROUTING_NONE); 123 render_view_host_ = new RenderViewHost(site_instance, this, MSG_ROUTING_NONE);
129 render_view_host_->AllowBindings(BindingsPolicy::EXTENSION); 124 render_view_host_->AllowBindings(BindingsPolicy::EXTENSION);
130 if (enable_dom_automation_) 125 if (enable_dom_automation_)
131 render_view_host_->AllowBindings(BindingsPolicy::DOM_AUTOMATION); 126 render_view_host_->AllowBindings(BindingsPolicy::DOM_AUTOMATION);
132
133 #if defined(TOOLKIT_VIEWS)
134 // Listen for view close requests, so that we can dismiss a hosted pop-up
135 // view, if necessary.
136 registrar_.Add(this, NotificationType::EXTENSION_HOST_VIEW_SHOULD_CLOSE,
137 Source<Profile>(profile_));
138 #endif
139 } 127 }
140 128
141 ExtensionHost::~ExtensionHost() { 129 ExtensionHost::~ExtensionHost() {
142 DismissPopup();
143 NotificationService::current()->Notify( 130 NotificationService::current()->Notify(
144 NotificationType::EXTENSION_HOST_DESTROYED, 131 NotificationType::EXTENSION_HOST_DESTROYED,
145 Source<Profile>(profile_), 132 Source<Profile>(profile_),
146 Details<ExtensionHost>(this)); 133 Details<ExtensionHost>(this));
147 ProcessCreationQueue::get()->Remove(this); 134 ProcessCreationQueue::get()->Remove(this);
148 render_view_host_->Shutdown(); // deletes render_view_host 135 render_view_host_->Shutdown(); // deletes render_view_host
149 } 136 }
150 137
151 void ExtensionHost::CreateView(Browser* browser) { 138 void ExtensionHost::CreateView(Browser* browser) {
152 #if defined(TOOLKIT_VIEWS) 139 #if defined(TOOLKIT_VIEWS)
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
222 } 209 }
223 210
224 void ExtensionHost::Observe(NotificationType type, 211 void ExtensionHost::Observe(NotificationType type,
225 const NotificationSource& source, 212 const NotificationSource& source,
226 const NotificationDetails& details) { 213 const NotificationDetails& details) {
227 if (type == NotificationType::EXTENSION_BACKGROUND_PAGE_READY) { 214 if (type == NotificationType::EXTENSION_BACKGROUND_PAGE_READY) {
228 DCHECK(extension_->GetBackgroundPageReady()); 215 DCHECK(extension_->GetBackgroundPageReady());
229 NavigateToURL(url_); 216 NavigateToURL(url_);
230 } else if (type == NotificationType::BROWSER_THEME_CHANGED) { 217 } else if (type == NotificationType::BROWSER_THEME_CHANGED) {
231 InsertThemeCSS(); 218 InsertThemeCSS();
232 #if defined(TOOLKIT_VIEWS)
233 } else if (type == NotificationType::EXTENSION_HOST_VIEW_SHOULD_CLOSE) {
234 // If we aren't the host of the popup, then disregard the notification.
235 if (!child_popup_ ||
236 Details<ExtensionHost>(child_popup_->host()) != details)
237 return;
238
239 DismissPopup();
240 #endif
241 } else { 219 } else {
242 NOTREACHED(); 220 NOTREACHED();
243 } 221 }
244 } 222 }
245 223
246 void ExtensionHost::UpdatePreferredSize(const gfx::Size& new_size) { 224 void ExtensionHost::UpdatePreferredSize(const gfx::Size& new_size) {
247 if (view_.get()) 225 if (view_.get())
248 view_->UpdatePreferredSize(new_size); 226 view_->UpdatePreferredSize(new_size);
249 } 227 }
250 228
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
317 while (pos != std::string::npos) { 295 while (pos != std::string::npos) {
318 css.replace(pos, 12, hex_color_string); 296 css.replace(pos, 12, hex_color_string);
319 pos = css.find(kToolstripTextColorSubstitution); 297 pos = css.find(kToolstripTextColorSubstitution);
320 } 298 }
321 299
322 // As a toolstrip, inject our toolstrip CSS to make it easier for toolstrips 300 // As a toolstrip, inject our toolstrip CSS to make it easier for toolstrips
323 // to blend in with the chrome UI. 301 // to blend in with the chrome UI.
324 render_view_host()->InsertCSSInWebFrame(L"", css, "ToolstripThemeCSS"); 302 render_view_host()->InsertCSSInWebFrame(L"", css, "ToolstripThemeCSS");
325 } 303 }
326 304
327 void ExtensionHost::DismissPopup() {
328 #if defined(TOOLKIT_VIEWS)
329 if (child_popup_) {
330 child_popup_->Hide();
331 child_popup_->DetachFromBrowser();
332 delete child_popup_;
333 child_popup_ = NULL;
334
335 PopupEventRouter::OnPopupClosed(GetBrowser()->profile(),
336 view()->render_view_host()->routing_id());
337 }
338 #endif
339 }
340
341 #if defined(TOOLKIT_VIEWS)
342 void ExtensionHost::BubbleBrowserWindowMoved(BrowserBubble* bubble) {
343 DismissPopup();
344 }
345 void ExtensionHost::BubbleBrowserWindowClosing(BrowserBubble* bubble) {
346 DismissPopup();
347 }
348
349 void ExtensionHost::BubbleGotFocus(BrowserBubble* bubble) {
350 }
351
352 void ExtensionHost::BubbleLostFocus(BrowserBubble* bubble) {
353 // TODO(twiz): Dismiss the pop-up upon loss of focus of the bubble, but not
354 // if the focus is transitioning to the host which owns the popup!
355 // DismissPopup();
356 }
357 #endif // defined(TOOLKIT_VIEWS)
358
359 void ExtensionHost::DidStopLoading() { 305 void ExtensionHost::DidStopLoading() {
360 bool notify = !did_stop_loading_; 306 bool notify = !did_stop_loading_;
361 did_stop_loading_ = true; 307 did_stop_loading_ = true;
362 if (extension_host_type_ == ViewType::EXTENSION_TOOLSTRIP || 308 if (extension_host_type_ == ViewType::EXTENSION_TOOLSTRIP ||
363 extension_host_type_ == ViewType::EXTENSION_MOLE || 309 extension_host_type_ == ViewType::EXTENSION_MOLE ||
364 extension_host_type_ == ViewType::EXTENSION_POPUP) { 310 extension_host_type_ == ViewType::EXTENSION_POPUP) {
365 #if defined(TOOLKIT_VIEWS) 311 #if defined(TOOLKIT_VIEWS)
366 if (view_.get()) 312 if (view_.get())
367 view_->DidStopLoading(); 313 view_->DidStopLoading();
368 #endif 314 #endif
(...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after
619 window_id = ExtensionTabUtil::GetWindowId( 565 window_id = ExtensionTabUtil::GetWindowId(
620 const_cast<ExtensionHost* >(this)->GetBrowser()); 566 const_cast<ExtensionHost* >(this)->GetBrowser());
621 } else if (extension_host_type_ == ViewType::EXTENSION_BACKGROUND_PAGE) { 567 } else if (extension_host_type_ == ViewType::EXTENSION_BACKGROUND_PAGE) {
622 // Background page is not attached to any browser window, so pass -1. 568 // Background page is not attached to any browser window, so pass -1.
623 window_id = -1; 569 window_id = -1;
624 } else { 570 } else {
625 NOTREACHED(); 571 NOTREACHED();
626 } 572 }
627 return window_id; 573 return window_id;
628 } 574 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_host.h ('k') | chrome/browser/extensions/extension_popup_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698