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

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

Issue 7327007: Moving notification types which are chrome specific to a new header file chrome_notification_type... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 years, 5 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/memory/singleton.h" 9 #include "base/memory/singleton.h"
10 #include "base/message_loop.h" 10 #include "base/message_loop.h"
11 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
12 #include "base/string_util.h" 12 #include "base/string_util.h"
13 #include "base/utf_string_conversions.h" 13 #include "base/utf_string_conversions.h"
14 #include "chrome/browser/browser_shutdown.h" 14 #include "chrome/browser/browser_shutdown.h"
15 #include "chrome/browser/extensions/extension_service.h" 15 #include "chrome/browser/extensions/extension_service.h"
16 #include "chrome/browser/extensions/extension_tabs_module.h" 16 #include "chrome/browser/extensions/extension_tabs_module.h"
17 #include "chrome/browser/file_select_helper.h" 17 #include "chrome/browser/file_select_helper.h"
18 #include "chrome/browser/platform_util.h" 18 #include "chrome/browser/platform_util.h"
19 #include "chrome/browser/profiles/profile.h" 19 #include "chrome/browser/profiles/profile.h"
20 #include "chrome/browser/renderer_preferences_util.h" 20 #include "chrome/browser/renderer_preferences_util.h"
21 #include "chrome/browser/tab_contents/popup_menu_helper_mac.h" 21 #include "chrome/browser/tab_contents/popup_menu_helper_mac.h"
22 #include "chrome/browser/tabs/tab_strip_model.h" 22 #include "chrome/browser/tabs/tab_strip_model.h"
23 #include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h" 23 #include "chrome/browser/ui/app_modal_dialogs/message_box_handler.h"
24 #include "chrome/browser/ui/browser.h" 24 #include "chrome/browser/ui/browser.h"
25 #include "chrome/browser/ui/browser_list.h" 25 #include "chrome/browser/ui/browser_list.h"
26 #include "chrome/browser/ui/browser_window.h" 26 #include "chrome/browser/ui/browser_window.h"
27 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 27 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
28 #include "chrome/browser/ui/webui/chrome_web_ui_factory.h" 28 #include "chrome/browser/ui/webui/chrome_web_ui_factory.h"
29 #include "chrome/common/chrome_constants.h" 29 #include "chrome/common/chrome_constants.h"
30 #include "chrome/common/chrome_notification_types.h"
30 #include "chrome/common/extensions/extension.h" 31 #include "chrome/common/extensions/extension.h"
31 #include "chrome/common/extensions/extension_constants.h" 32 #include "chrome/common/extensions/extension_constants.h"
32 #include "chrome/common/extensions/extension_messages.h" 33 #include "chrome/common/extensions/extension_messages.h"
33 #include "chrome/common/render_messages.h" 34 #include "chrome/common/render_messages.h"
34 #include "chrome/common/url_constants.h" 35 #include "chrome/common/url_constants.h"
35 #include "content/browser/browsing_instance.h" 36 #include "content/browser/browsing_instance.h"
36 #include "content/browser/content_browser_client.h" 37 #include "content/browser/content_browser_client.h"
37 #include "content/browser/renderer_host/browser_render_process_host.h" 38 #include "content/browser/renderer_host/browser_render_process_host.h"
38 #include "content/browser/renderer_host/render_process_host.h" 39 #include "content/browser/renderer_host/render_process_host.h"
39 #include "content/browser/renderer_host/render_view_host.h" 40 #include "content/browser/renderer_host/render_view_host.h"
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 extension_function_dispatcher_(profile_, this)), 140 extension_function_dispatcher_(profile_, this)),
140 extension_host_type_(host_type), 141 extension_host_type_(host_type),
141 associated_tab_contents_(NULL) { 142 associated_tab_contents_(NULL) {
142 render_view_host_ = new RenderViewHost(site_instance, this, MSG_ROUTING_NONE, 143 render_view_host_ = new RenderViewHost(site_instance, this, MSG_ROUTING_NONE,
143 NULL); 144 NULL);
144 if (enable_dom_automation_) 145 if (enable_dom_automation_)
145 render_view_host_->AllowBindings(BindingsPolicy::DOM_AUTOMATION); 146 render_view_host_->AllowBindings(BindingsPolicy::DOM_AUTOMATION);
146 147
147 // Listen for when the render process' handle is available so we can add it 148 // Listen for when the render process' handle is available so we can add it
148 // to the task manager then. 149 // to the task manager then.
149 registrar_.Add(this, NotificationType::RENDERER_PROCESS_CREATED, 150 registrar_.Add(this, content::NOTIFICATION_RENDERER_PROCESS_CREATED,
150 Source<RenderProcessHost>(render_process_host())); 151 Source<RenderProcessHost>(render_process_host()));
151 // Listen for when an extension is unloaded from the same profile, as it may 152 // Listen for when an extension is unloaded from the same profile, as it may
152 // be the same extension that this points to. 153 // be the same extension that this points to.
153 registrar_.Add(this, NotificationType::EXTENSION_UNLOADED, 154 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_UNLOADED,
154 Source<Profile>(profile_)); 155 Source<Profile>(profile_));
155 } 156 }
156 157
157 ExtensionHost::~ExtensionHost() { 158 ExtensionHost::~ExtensionHost() {
158 NotificationService::current()->Notify( 159 NotificationService::current()->Notify(
159 NotificationType::EXTENSION_HOST_DESTROYED, 160 chrome::NOTIFICATION_EXTENSION_HOST_DESTROYED,
160 Source<Profile>(profile_), 161 Source<Profile>(profile_),
161 Details<ExtensionHost>(this)); 162 Details<ExtensionHost>(this));
162 ProcessCreationQueue::GetInstance()->Remove(this); 163 ProcessCreationQueue::GetInstance()->Remove(this);
163 GetJavaScriptDialogCreatorInstance()->ResetJavaScriptState(this); 164 GetJavaScriptDialogCreatorInstance()->ResetJavaScriptState(this);
164 render_view_host_->Shutdown(); // deletes render_view_host 165 render_view_host_->Shutdown(); // deletes render_view_host
165 } 166 }
166 167
167 void ExtensionHost::CreateView(Browser* browser) { 168 void ExtensionHost::CreateView(Browser* browser) {
168 #if defined(TOOLKIT_VIEWS) 169 #if defined(TOOLKIT_VIEWS)
169 view_.reset(new ExtensionView(this, browser)); 170 view_.reset(new ExtensionView(this, browser));
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 if (url.SchemeIs(chrome::kExtensionScheme) && url.host() != extension_id()) { 252 if (url.SchemeIs(chrome::kExtensionScheme) && url.host() != extension_id()) {
252 // TODO(erikkay) communicate this back to the caller? 253 // TODO(erikkay) communicate this back to the caller?
253 return; 254 return;
254 } 255 }
255 256
256 url_ = url; 257 url_ = url;
257 258
258 if (!is_background_page() && 259 if (!is_background_page() &&
259 !profile_->GetExtensionService()->IsBackgroundPageReady(extension_)) { 260 !profile_->GetExtensionService()->IsBackgroundPageReady(extension_)) {
260 // Make sure the background page loads before any others. 261 // Make sure the background page loads before any others.
261 registrar_.Add(this, NotificationType::EXTENSION_BACKGROUND_PAGE_READY, 262 registrar_.Add(this, chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY,
262 Source<Extension>(extension_)); 263 Source<Extension>(extension_));
263 return; 264 return;
264 } 265 }
265 266
266 render_view_host_->NavigateToURL(url_); 267 render_view_host_->NavigateToURL(url_);
267 } 268 }
268 269
269 void ExtensionHost::Observe(NotificationType type, 270 void ExtensionHost::Observe(int type,
270 const NotificationSource& source, 271 const NotificationSource& source,
271 const NotificationDetails& details) { 272 const NotificationDetails& details) {
272 switch (type.value) { 273 switch (type) {
273 case NotificationType::EXTENSION_BACKGROUND_PAGE_READY: 274 case chrome::NOTIFICATION_EXTENSION_BACKGROUND_PAGE_READY:
274 DCHECK(profile_->GetExtensionService()-> 275 DCHECK(profile_->GetExtensionService()->
275 IsBackgroundPageReady(extension_)); 276 IsBackgroundPageReady(extension_));
276 NavigateToURL(url_); 277 NavigateToURL(url_);
277 break; 278 break;
278 case NotificationType::RENDERER_PROCESS_CREATED: 279 case content::NOTIFICATION_RENDERER_PROCESS_CREATED:
279 NotificationService::current()->Notify( 280 NotificationService::current()->Notify(
280 NotificationType::EXTENSION_PROCESS_CREATED, 281 chrome::NOTIFICATION_EXTENSION_PROCESS_CREATED,
281 Source<Profile>(profile_), 282 Source<Profile>(profile_),
282 Details<ExtensionHost>(this)); 283 Details<ExtensionHost>(this));
283 break; 284 break;
284 case NotificationType::EXTENSION_UNLOADED: 285 case chrome::NOTIFICATION_EXTENSION_UNLOADED:
285 // The extension object will be deleted after this notification has been 286 // The extension object will be deleted after this notification has been
286 // sent. NULL it out so that dirty pointer issues don't arise in cases 287 // sent. NULL it out so that dirty pointer issues don't arise in cases
287 // when multiple ExtensionHost objects pointing to the same Extension are 288 // when multiple ExtensionHost objects pointing to the same Extension are
288 // present. 289 // present.
289 if (extension_ == Details<UnloadedExtensionInfo>(details)->extension) 290 if (extension_ == Details<UnloadedExtensionInfo>(details)->extension)
290 extension_ = NULL; 291 extension_ = NULL;
291 break; 292 break;
292 default: 293 default:
293 NOTREACHED() << "Unexpected notification sent."; 294 NOTREACHED() << "Unexpected notification sent.";
294 break; 295 break;
(...skipping 30 matching lines...) Expand all
325 // its pointer to it NULLed out so that any attempt to unload a dirty pointer 326 // its pointer to it NULLed out so that any attempt to unload a dirty pointer
326 // will be averted. 327 // will be averted.
327 if (!extension_) 328 if (!extension_)
328 return; 329 return;
329 330
330 // TODO(aa): This is suspicious. There can be multiple views in an extension, 331 // TODO(aa): This is suspicious. There can be multiple views in an extension,
331 // and they aren't all going to use ExtensionHost. This should be in someplace 332 // and they aren't all going to use ExtensionHost. This should be in someplace
332 // more central, like EPM maybe. 333 // more central, like EPM maybe.
333 DCHECK_EQ(render_view_host_, render_view_host); 334 DCHECK_EQ(render_view_host_, render_view_host);
334 NotificationService::current()->Notify( 335 NotificationService::current()->Notify(
335 NotificationType::EXTENSION_PROCESS_TERMINATED, 336 chrome::NOTIFICATION_EXTENSION_PROCESS_TERMINATED,
336 Source<Profile>(profile_), 337 Source<Profile>(profile_),
337 Details<ExtensionHost>(this)); 338 Details<ExtensionHost>(this));
338 } 339 }
339 340
340 void ExtensionHost::DidNavigate(RenderViewHost* render_view_host, 341 void ExtensionHost::DidNavigate(RenderViewHost* render_view_host,
341 const ViewHostMsg_FrameNavigate_Params& params) { 342 const ViewHostMsg_FrameNavigate_Params& params) {
342 // We only care when the outer frame changes. 343 // We only care when the outer frame changes.
343 if (!PageTransition::IsMainFrame(params.transition)) 344 if (!PageTransition::IsMainFrame(params.transition))
344 return; 345 return;
345 346
(...skipping 24 matching lines...) Expand all
370 if (extension_host_type_ == ViewType::EXTENSION_POPUP || 371 if (extension_host_type_ == ViewType::EXTENSION_POPUP ||
371 extension_host_type_ == ViewType::EXTENSION_DIALOG || 372 extension_host_type_ == ViewType::EXTENSION_DIALOG ||
372 extension_host_type_ == ViewType::EXTENSION_INFOBAR) { 373 extension_host_type_ == ViewType::EXTENSION_INFOBAR) {
373 #if defined(TOOLKIT_VIEWS) 374 #if defined(TOOLKIT_VIEWS)
374 if (view_.get()) 375 if (view_.get())
375 view_->DidStopLoading(); 376 view_->DidStopLoading();
376 #endif 377 #endif
377 } 378 }
378 if (notify) { 379 if (notify) {
379 NotificationService::current()->Notify( 380 NotificationService::current()->Notify(
380 NotificationType::EXTENSION_HOST_DID_STOP_LOADING, 381 chrome::NOTIFICATION_EXTENSION_HOST_DID_STOP_LOADING,
381 Source<Profile>(profile_), 382 Source<Profile>(profile_),
382 Details<ExtensionHost>(this)); 383 Details<ExtensionHost>(this));
383 if (extension_host_type_ == ViewType::EXTENSION_BACKGROUND_PAGE) { 384 if (extension_host_type_ == ViewType::EXTENSION_BACKGROUND_PAGE) {
384 UMA_HISTOGRAM_TIMES("Extensions.BackgroundPageLoadTime", 385 UMA_HISTOGRAM_TIMES("Extensions.BackgroundPageLoadTime",
385 since_created_.Elapsed()); 386 since_created_.Elapsed());
386 } else if (extension_host_type_ == ViewType::EXTENSION_DIALOG) { 387 } else if (extension_host_type_ == ViewType::EXTENSION_DIALOG) {
387 UMA_HISTOGRAM_TIMES("Extensions.DialogLoadTime", 388 UMA_HISTOGRAM_TIMES("Extensions.DialogLoadTime",
388 since_created_.Elapsed()); 389 since_created_.Elapsed());
389 } else if (extension_host_type_ == ViewType::EXTENSION_POPUP) { 390 } else if (extension_host_type_ == ViewType::EXTENSION_POPUP) {
390 UMA_HISTOGRAM_TIMES("Extensions.PopupLoadTime", 391 UMA_HISTOGRAM_TIMES("Extensions.PopupLoadTime",
(...skipping 22 matching lines...) Expand all
413 default: 414 default:
414 break; // No style sheet for other types, at the moment. 415 break; // No style sheet for other types, at the moment.
415 } 416 }
416 } 417 }
417 } 418 }
418 419
419 void ExtensionHost::DocumentOnLoadCompletedInMainFrame(RenderViewHost* rvh, 420 void ExtensionHost::DocumentOnLoadCompletedInMainFrame(RenderViewHost* rvh,
420 int32 page_id) { 421 int32 page_id) {
421 if (ViewType::EXTENSION_POPUP == GetRenderViewType()) { 422 if (ViewType::EXTENSION_POPUP == GetRenderViewType()) {
422 NotificationService::current()->Notify( 423 NotificationService::current()->Notify(
423 NotificationType::EXTENSION_POPUP_VIEW_READY, 424 chrome::NOTIFICATION_EXTENSION_POPUP_VIEW_READY,
424 Source<Profile>(profile_), 425 Source<Profile>(profile_),
425 Details<ExtensionHost>(this)); 426 Details<ExtensionHost>(this));
426 } 427 }
427 } 428 }
428 429
429 void ExtensionHost::RunJavaScriptMessage(const RenderViewHost* rvh, 430 void ExtensionHost::RunJavaScriptMessage(const RenderViewHost* rvh,
430 const string16& message, 431 const string16& message,
431 const string16& default_prompt, 432 const string16& default_prompt,
432 const GURL& frame_url, 433 const GURL& frame_url,
433 const int flags, 434 const int flags,
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 render_view_host()->JavaScriptDialogClosed(reply_msg, 485 render_view_host()->JavaScriptDialogClosed(reply_msg,
485 success, 486 success,
486 user_input); 487 user_input);
487 } 488 }
488 489
489 void ExtensionHost::Close(RenderViewHost* render_view_host) { 490 void ExtensionHost::Close(RenderViewHost* render_view_host) {
490 if (extension_host_type_ == ViewType::EXTENSION_POPUP || 491 if (extension_host_type_ == ViewType::EXTENSION_POPUP ||
491 extension_host_type_ == ViewType::EXTENSION_DIALOG || 492 extension_host_type_ == ViewType::EXTENSION_DIALOG ||
492 extension_host_type_ == ViewType::EXTENSION_INFOBAR) { 493 extension_host_type_ == ViewType::EXTENSION_INFOBAR) {
493 NotificationService::current()->Notify( 494 NotificationService::current()->Notify(
494 NotificationType::EXTENSION_HOST_VIEW_SHOULD_CLOSE, 495 chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE,
495 Source<Profile>(profile_), 496 Source<Profile>(profile_),
496 Details<ExtensionHost>(this)); 497 Details<ExtensionHost>(this));
497 } 498 }
498 } 499 }
499 500
500 RendererPreferences ExtensionHost::GetRendererPrefs(Profile* profile) const { 501 RendererPreferences ExtensionHost::GetRendererPrefs(Profile* profile) const {
501 RendererPreferences preferences; 502 RendererPreferences preferences;
502 503
503 TabContents* associated_contents = GetAssociatedTabContents(); 504 TabContents* associated_contents = GetAssociatedTabContents();
504 if (associated_contents) 505 if (associated_contents)
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
730 *is_keyboard_shortcut = true; 731 *is_keyboard_shortcut = true;
731 } 732 }
732 return false; 733 return false;
733 } 734 }
734 735
735 void ExtensionHost::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { 736 void ExtensionHost::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) {
736 if (extension_host_type_ == ViewType::EXTENSION_POPUP) { 737 if (extension_host_type_ == ViewType::EXTENSION_POPUP) {
737 if (event.type == NativeWebKeyboardEvent::RawKeyDown && 738 if (event.type == NativeWebKeyboardEvent::RawKeyDown &&
738 event.windowsKeyCode == ui::VKEY_ESCAPE) { 739 event.windowsKeyCode == ui::VKEY_ESCAPE) {
739 NotificationService::current()->Notify( 740 NotificationService::current()->Notify(
740 NotificationType::EXTENSION_HOST_VIEW_SHOULD_CLOSE, 741 chrome::NOTIFICATION_EXTENSION_HOST_VIEW_SHOULD_CLOSE,
741 Source<Profile>(profile_), 742 Source<Profile>(profile_),
742 Details<ExtensionHost>(this)); 743 Details<ExtensionHost>(this));
743 return; 744 return;
744 } 745 }
745 } 746 }
746 UnhandledKeyboardEvent(event); 747 UnhandledKeyboardEvent(event);
747 } 748 }
748 749
749 void ExtensionHost::HandleMouseMove() { 750 void ExtensionHost::HandleMouseMove() {
750 #if defined(OS_WIN) 751 #if defined(OS_WIN)
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
803 } 804 }
804 } 805 }
805 806
806 void ExtensionHost::OnRunFileChooser( 807 void ExtensionHost::OnRunFileChooser(
807 const ViewHostMsg_RunFileChooser_Params& params) { 808 const ViewHostMsg_RunFileChooser_Params& params) {
808 if (file_select_helper_.get() == NULL) 809 if (file_select_helper_.get() == NULL)
809 file_select_helper_.reset(new FileSelectHelper(profile())); 810 file_select_helper_.reset(new FileSelectHelper(profile()));
810 file_select_helper_->RunFileChooser(render_view_host_, 811 file_select_helper_->RunFileChooser(render_view_host_,
811 GetAssociatedTabContents(), params); 812 GetAssociatedTabContents(), params);
812 } 813 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_host.h ('k') | chrome/browser/extensions/extension_infobar_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698