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

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

Issue 402673003: Move ExtensionHostMsg_PostMessage IPC handling from (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 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 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/chrome_extension_web_contents_observer.h" 5 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
6 6
7 #include "chrome/browser/extensions/api/messaging/message_service.h"
8 #include "chrome/browser/extensions/error_console/error_console.h" 7 #include "chrome/browser/extensions/error_console/error_console.h"
9 #include "chrome/browser/extensions/extension_service.h" 8 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/common/extensions/chrome_extension_messages.h" 9 #include "chrome/common/extensions/chrome_extension_messages.h"
11 #include "content/public/browser/browser_context.h" 10 #include "content/public/browser/browser_context.h"
12 #include "content/public/browser/render_process_host.h" 11 #include "content/public/browser/render_process_host.h"
13 #include "content/public/browser/render_view_host.h" 12 #include "content/public/browser/render_view_host.h"
14 #include "extensions/browser/extension_registry.h" 13 #include "extensions/browser/extension_registry.h"
15 #include "extensions/browser/extension_system.h" 14 #include "extensions/browser/extension_system.h"
16 #include "extensions/common/api/messaging/message.h"
17 #include "extensions/common/extension_messages.h" 15 #include "extensions/common/extension_messages.h"
Lei Zhang 2014/07/17 17:56:42 This can be removed too.
not at google - send to devlin 2014/07/17 19:38:42 Done.
18 #include "extensions/common/extension_urls.h" 16 #include "extensions/common/extension_urls.h"
19 17
20 using content::BrowserContext; 18 using content::BrowserContext;
21 19
22 DEFINE_WEB_CONTENTS_USER_DATA_KEY( 20 DEFINE_WEB_CONTENTS_USER_DATA_KEY(
23 extensions::ChromeExtensionWebContentsObserver); 21 extensions::ChromeExtensionWebContentsObserver);
24 22
25 namespace extensions { 23 namespace extensions {
26 24
27 ChromeExtensionWebContentsObserver::ChromeExtensionWebContentsObserver( 25 ChromeExtensionWebContentsObserver::ChromeExtensionWebContentsObserver(
28 content::WebContents* web_contents) 26 content::WebContents* web_contents)
29 : ExtensionWebContentsObserver(web_contents) {} 27 : ExtensionWebContentsObserver(web_contents) {}
30 28
31 ChromeExtensionWebContentsObserver::~ChromeExtensionWebContentsObserver() {} 29 ChromeExtensionWebContentsObserver::~ChromeExtensionWebContentsObserver() {}
32 30
33 void ChromeExtensionWebContentsObserver::RenderViewCreated( 31 void ChromeExtensionWebContentsObserver::RenderViewCreated(
34 content::RenderViewHost* render_view_host) { 32 content::RenderViewHost* render_view_host) {
35 ReloadIfTerminated(render_view_host); 33 ReloadIfTerminated(render_view_host);
36 ExtensionWebContentsObserver::RenderViewCreated(render_view_host); 34 ExtensionWebContentsObserver::RenderViewCreated(render_view_host);
37 } 35 }
38 36
39 bool ChromeExtensionWebContentsObserver::OnMessageReceived( 37 bool ChromeExtensionWebContentsObserver::OnMessageReceived(
40 const IPC::Message& message) {
41 bool handled = true;
42 IPC_BEGIN_MESSAGE_MAP(ChromeExtensionWebContentsObserver, message)
43 IPC_MESSAGE_HANDLER(ExtensionHostMsg_PostMessage, OnPostMessage)
44 IPC_MESSAGE_UNHANDLED(handled = false)
45 IPC_END_MESSAGE_MAP()
46 return handled;
47 }
48
49 bool ChromeExtensionWebContentsObserver::OnMessageReceived(
50 const IPC::Message& message, 38 const IPC::Message& message,
51 content::RenderFrameHost* render_frame_host) { 39 content::RenderFrameHost* render_frame_host) {
52 #if defined(ENABLE_EXTENSIONS) 40 #if defined(ENABLE_EXTENSIONS)
53 bool handled = true; 41 bool handled = true;
54 IPC_BEGIN_MESSAGE_MAP(ChromeExtensionWebContentsObserver, message) 42 IPC_BEGIN_MESSAGE_MAP(ChromeExtensionWebContentsObserver, message)
55 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DetailedConsoleMessageAdded, 43 IPC_MESSAGE_HANDLER(ChromeViewHostMsg_DetailedConsoleMessageAdded,
56 OnDetailedConsoleMessageAdded) 44 OnDetailedConsoleMessageAdded)
57 IPC_MESSAGE_UNHANDLED(handled = false) 45 IPC_MESSAGE_UNHANDLED(handled = false)
58 IPC_END_MESSAGE_MAP() 46 IPC_END_MESSAGE_MAP()
59 #else 47 #else
(...skipping 24 matching lines...) Expand all
84 source, 72 source,
85 message, 73 message,
86 stack_trace, 74 stack_trace,
87 web_contents()->GetLastCommittedURL(), 75 web_contents()->GetLastCommittedURL(),
88 static_cast<logging::LogSeverity>(severity_level), 76 static_cast<logging::LogSeverity>(severity_level),
89 render_view_host->GetRoutingID(), 77 render_view_host->GetRoutingID(),
90 render_view_host->GetProcess()->GetID()))); 78 render_view_host->GetProcess()->GetID())));
91 #endif 79 #endif
92 } 80 }
93 81
94 void ChromeExtensionWebContentsObserver::OnPostMessage(int port_id,
95 const Message& message) {
96 MessageService* message_service = MessageService::Get(browser_context());
97 if (message_service) {
98 message_service->PostMessage(port_id, message);
99 }
100 }
101
102 void ChromeExtensionWebContentsObserver::ReloadIfTerminated( 82 void ChromeExtensionWebContentsObserver::ReloadIfTerminated(
103 content::RenderViewHost* render_view_host) { 83 content::RenderViewHost* render_view_host) {
104 std::string extension_id = GetExtensionId(render_view_host); 84 std::string extension_id = GetExtensionId(render_view_host);
105 if (extension_id.empty()) 85 if (extension_id.empty())
106 return; 86 return;
107 87
108 ExtensionRegistry* registry = ExtensionRegistry::Get(browser_context()); 88 ExtensionRegistry* registry = ExtensionRegistry::Get(browser_context());
109 89
110 // Reload the extension if it has crashed. 90 // Reload the extension if it has crashed.
111 // TODO(yoz): This reload doesn't happen synchronously for unpacked 91 // TODO(yoz): This reload doesn't happen synchronously for unpacked
112 // extensions. It seems to be fast enough, but there is a race. 92 // extensions. It seems to be fast enough, but there is a race.
113 // We should delay loading until the extension has reloaded. 93 // We should delay loading until the extension has reloaded.
114 if (registry->GetExtensionById(extension_id, ExtensionRegistry::TERMINATED)) { 94 if (registry->GetExtensionById(extension_id, ExtensionRegistry::TERMINATED)) {
115 ExtensionSystem::Get(browser_context())-> 95 ExtensionSystem::Get(browser_context())->
116 extension_service()->ReloadExtension(extension_id); 96 extension_service()->ReloadExtension(extension_id);
117 } 97 }
118 } 98 }
119 99
120 } // namespace extensions 100 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698