OLD | NEW |
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 "apps/shell/renderer/shell_content_renderer_client.h" | 5 #include "extensions/shell/renderer/shell_content_renderer_client.h" |
6 | 6 |
7 #include "apps/shell/common/shell_extensions_client.h" | |
8 #include "apps/shell/renderer/shell_dispatcher_delegate.h" | |
9 #include "apps/shell/renderer/shell_extensions_renderer_client.h" | |
10 #include "apps/shell/renderer/shell_renderer_main_delegate.h" | |
11 #include "content/public/renderer/render_frame.h" | 7 #include "content/public/renderer/render_frame.h" |
12 #include "content/public/renderer/render_frame_observer.h" | 8 #include "content/public/renderer/render_frame_observer.h" |
13 #include "content/public/renderer/render_frame_observer_tracker.h" | 9 #include "content/public/renderer/render_frame_observer_tracker.h" |
14 #include "content/public/renderer/render_thread.h" | 10 #include "content/public/renderer/render_thread.h" |
15 #include "extensions/common/extensions_client.h" | 11 #include "extensions/common/extensions_client.h" |
16 #include "extensions/renderer/dispatcher.h" | 12 #include "extensions/renderer/dispatcher.h" |
17 #include "extensions/renderer/extension_helper.h" | 13 #include "extensions/renderer/extension_helper.h" |
| 14 #include "extensions/shell/common/shell_extensions_client.h" |
| 15 #include "extensions/shell/renderer/shell_dispatcher_delegate.h" |
| 16 #include "extensions/shell/renderer/shell_extensions_renderer_client.h" |
| 17 #include "extensions/shell/renderer/shell_renderer_main_delegate.h" |
18 | 18 |
19 using blink::WebFrame; | 19 using blink::WebFrame; |
20 using blink::WebString; | 20 using blink::WebString; |
21 using content::RenderThread; | 21 using content::RenderThread; |
22 | 22 |
23 namespace apps { | 23 namespace extensions { |
24 | 24 |
25 namespace { | 25 namespace { |
26 | 26 |
27 // TODO: promote ExtensionFrameHelper to a common place and share with this. | 27 // TODO: promote ExtensionFrameHelper to a common place and share with this. |
28 class ShellFrameHelper | 28 class ShellFrameHelper |
29 : public content::RenderFrameObserver, | 29 : public content::RenderFrameObserver, |
30 public content::RenderFrameObserverTracker<ShellFrameHelper> { | 30 public content::RenderFrameObserverTracker<ShellFrameHelper> { |
31 public: | 31 public: |
32 ShellFrameHelper(content::RenderFrame* render_frame, | 32 ShellFrameHelper(content::RenderFrame* render_frame, |
33 extensions::Dispatcher* extension_dispatcher); | 33 Dispatcher* extension_dispatcher); |
34 virtual ~ShellFrameHelper(); | 34 virtual ~ShellFrameHelper(); |
35 | 35 |
36 // RenderFrameObserver implementation. | 36 // RenderFrameObserver implementation. |
37 virtual void WillReleaseScriptContext(v8::Handle<v8::Context>, | 37 virtual void WillReleaseScriptContext(v8::Handle<v8::Context>, |
38 int world_id) OVERRIDE; | 38 int world_id) OVERRIDE; |
39 | 39 |
40 private: | 40 private: |
41 extensions::Dispatcher* extension_dispatcher_; | 41 Dispatcher* extension_dispatcher_; |
42 | 42 |
43 DISALLOW_COPY_AND_ASSIGN(ShellFrameHelper); | 43 DISALLOW_COPY_AND_ASSIGN(ShellFrameHelper); |
44 }; | 44 }; |
45 | 45 |
46 ShellFrameHelper::ShellFrameHelper(content::RenderFrame* render_frame, | 46 ShellFrameHelper::ShellFrameHelper(content::RenderFrame* render_frame, |
47 extensions::Dispatcher* extension_dispatcher) | 47 Dispatcher* extension_dispatcher) |
48 : content::RenderFrameObserver(render_frame), | 48 : content::RenderFrameObserver(render_frame), |
49 content::RenderFrameObserverTracker<ShellFrameHelper>(render_frame), | 49 content::RenderFrameObserverTracker<ShellFrameHelper>(render_frame), |
50 extension_dispatcher_(extension_dispatcher) {} | 50 extension_dispatcher_(extension_dispatcher) { |
| 51 } |
51 | 52 |
52 ShellFrameHelper::~ShellFrameHelper() {} | 53 ShellFrameHelper::~ShellFrameHelper() { |
| 54 } |
53 | 55 |
54 void ShellFrameHelper::WillReleaseScriptContext(v8::Handle<v8::Context> context, | 56 void ShellFrameHelper::WillReleaseScriptContext(v8::Handle<v8::Context> context, |
55 int world_id) { | 57 int world_id) { |
56 extension_dispatcher_->WillReleaseScriptContext( | 58 extension_dispatcher_->WillReleaseScriptContext( |
57 render_frame()->GetWebFrame(), context, world_id); | 59 render_frame()->GetWebFrame(), context, world_id); |
58 } | 60 } |
59 | 61 |
60 } // namespace | 62 } // namespace |
61 | 63 |
62 ShellContentRendererClient::ShellContentRendererClient( | 64 ShellContentRendererClient::ShellContentRendererClient( |
63 scoped_ptr<ShellRendererMainDelegate> delegate) | 65 scoped_ptr<ShellRendererMainDelegate> delegate) |
64 : delegate_(delegate.Pass()) { | 66 : delegate_(delegate.Pass()) { |
65 } | 67 } |
66 | 68 |
67 ShellContentRendererClient::~ShellContentRendererClient() {} | 69 ShellContentRendererClient::~ShellContentRendererClient() { |
| 70 } |
68 | 71 |
69 void ShellContentRendererClient::RenderThreadStarted() { | 72 void ShellContentRendererClient::RenderThreadStarted() { |
70 RenderThread* thread = RenderThread::Get(); | 73 RenderThread* thread = RenderThread::Get(); |
71 | 74 |
72 extensions_client_.reset(new ShellExtensionsClient); | 75 extensions_client_.reset(new ShellExtensionsClient); |
73 extensions::ExtensionsClient::Set(extensions_client_.get()); | 76 ExtensionsClient::Set(extensions_client_.get()); |
74 | 77 |
75 extensions_renderer_client_.reset(new ShellExtensionsRendererClient); | 78 extensions_renderer_client_.reset(new ShellExtensionsRendererClient); |
76 extensions::ExtensionsRendererClient::Set(extensions_renderer_client_.get()); | 79 ExtensionsRendererClient::Set(extensions_renderer_client_.get()); |
77 | 80 |
78 extension_dispatcher_delegate_.reset(new ShellDispatcherDelegate()); | 81 extension_dispatcher_delegate_.reset(new ShellDispatcherDelegate()); |
79 | 82 |
80 // Must be initialized after ExtensionsRendererClient. | 83 // Must be initialized after ExtensionsRendererClient. |
81 extension_dispatcher_.reset( | 84 extension_dispatcher_.reset( |
82 new extensions::Dispatcher(extension_dispatcher_delegate_.get())); | 85 new Dispatcher(extension_dispatcher_delegate_.get())); |
83 thread->AddObserver(extension_dispatcher_.get()); | 86 thread->AddObserver(extension_dispatcher_.get()); |
84 | 87 |
85 // TODO(jamescook): Init WebSecurityPolicy for chrome-extension: schemes. | 88 // TODO(jamescook): Init WebSecurityPolicy for chrome-extension: schemes. |
86 // See ChromeContentRendererClient for details. | 89 // See ChromeContentRendererClient for details. |
87 if (delegate_) | 90 if (delegate_) |
88 delegate_->OnThreadStarted(thread); | 91 delegate_->OnThreadStarted(thread); |
89 } | 92 } |
90 | 93 |
91 void ShellContentRendererClient::RenderFrameCreated( | 94 void ShellContentRendererClient::RenderFrameCreated( |
92 content::RenderFrame* render_frame) { | 95 content::RenderFrame* render_frame) { |
93 // ShellFrameHelper destroyes itself when the RenderFrame is destroyed. | 96 // ShellFrameHelper destroyes itself when the RenderFrame is destroyed. |
94 new ShellFrameHelper(render_frame, extension_dispatcher_.get()); | 97 new ShellFrameHelper(render_frame, extension_dispatcher_.get()); |
95 } | 98 } |
96 | 99 |
97 void ShellContentRendererClient::RenderViewCreated( | 100 void ShellContentRendererClient::RenderViewCreated( |
98 content::RenderView* render_view) { | 101 content::RenderView* render_view) { |
99 new extensions::ExtensionHelper(render_view, extension_dispatcher_.get()); | 102 new ExtensionHelper(render_view, extension_dispatcher_.get()); |
100 if (delegate_) | 103 if (delegate_) |
101 delegate_->OnViewCreated(render_view); | 104 delegate_->OnViewCreated(render_view); |
102 } | 105 } |
103 | 106 |
104 bool ShellContentRendererClient::WillSendRequest( | 107 bool ShellContentRendererClient::WillSendRequest( |
105 blink::WebFrame* frame, | 108 blink::WebFrame* frame, |
106 content::PageTransition transition_type, | 109 content::PageTransition transition_type, |
107 const GURL& url, | 110 const GURL& url, |
108 const GURL& first_party_for_cookies, | 111 const GURL& first_party_for_cookies, |
109 GURL* new_url) { | 112 GURL* new_url) { |
110 // TODO(jamescook): Cause an error for bad extension scheme requests? | 113 // TODO(jamescook): Cause an error for bad extension scheme requests? |
111 return false; | 114 return false; |
112 } | 115 } |
113 | 116 |
114 void ShellContentRendererClient::DidCreateScriptContext( | 117 void ShellContentRendererClient::DidCreateScriptContext( |
115 WebFrame* frame, v8::Handle<v8::Context> context, int extension_group, | 118 WebFrame* frame, |
| 119 v8::Handle<v8::Context> context, |
| 120 int extension_group, |
116 int world_id) { | 121 int world_id) { |
117 extension_dispatcher_->DidCreateScriptContext( | 122 extension_dispatcher_->DidCreateScriptContext( |
118 frame, context, extension_group, world_id); | 123 frame, context, extension_group, world_id); |
119 } | 124 } |
120 | 125 |
121 bool ShellContentRendererClient::ShouldEnableSiteIsolationPolicy() const { | 126 bool ShellContentRendererClient::ShouldEnableSiteIsolationPolicy() const { |
122 // Extension renderers don't need site isolation. | 127 // Extension renderers don't need site isolation. |
123 return false; | 128 return false; |
124 } | 129 } |
125 | 130 |
126 } // namespace apps | 131 } // namespace extensions |
OLD | NEW |