OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "content/renderer/browser_plugin/browser_plugin.h" | 5 #include "content/renderer/browser_plugin/browser_plugin.h" |
6 | 6 |
7 #include "base/atomic_sequence_num.h" | 7 #include "base/atomic_sequence_num.h" |
8 #include "base/id_map.h" | 8 #include "base/id_map.h" |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/process.h" | 10 #include "base/process.h" |
11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
12 #include "base/string_piece.h" | 12 #include "base/string_piece.h" |
13 #include "base/string_util.h" | 13 #include "base/string_util.h" |
14 #include "base/values.h" | 14 #include "base/values.h" |
15 #include "content/common/browser_plugin_messages.h" | 15 #include "content/common/browser_plugin_messages.h" |
16 #include "content/public/common/url_constants.h" | 16 #include "content/public/common/url_constants.h" |
17 #include "content/renderer/render_view_impl.h" | 17 #include "content/renderer/render_view_impl.h" |
18 #include "ipc/ipc_channel_handle.h" | 18 #include "ipc/ipc_channel_handle.h" |
19 #include "ppapi/proxy/host_dispatcher.h" | |
19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" | 20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" |
20 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h" | 21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPlugin.h" |
21 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" | 22 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPluginContainer.h" |
22 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 23 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
23 #include "webkit/plugins/ppapi/ppapi_webplugin_impl.h" | 24 #include "webkit/plugins/ppapi/ppapi_webplugin_impl.h" |
24 #include "webkit/plugins/webview_plugin.h" | 25 #include "webkit/plugins/webview_plugin.h" |
25 | 26 |
26 static int g_next_id = 0; | 27 static int g_next_id = 0; |
27 | 28 |
28 // The global list of all Browser Plugin Placeholders within a process. | 29 // The global list of all Browser Plugin Placeholders within a process. |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
71 NULL, | 72 NULL, |
72 render_view->GetWebkitPreferences(), | 73 render_view->GetWebkitPreferences(), |
73 html_data, | 74 html_data, |
74 GURL(chrome::kAboutBlankURL))), | 75 GURL(chrome::kAboutBlankURL))), |
75 plugin_(NULL) { | 76 plugin_(NULL) { |
76 id_ = ++g_next_id; | 77 id_ = ++g_next_id; |
77 Register(id_, this); | 78 Register(id_, this); |
78 | 79 |
79 // By default we do not navigate and simply stay with an | 80 // By default we do not navigate and simply stay with an |
80 // about:blank placeholder. | 81 // about:blank placeholder. |
81 gfx::Size size; | |
82 std::string src; | 82 std::string src; |
83 ParsePluginParameters(0, 0, "", &size, &src); | 83 ParseSrcAttribute("", &src); |
84 | 84 |
85 if (!src.empty()) { | 85 if (!src.empty()) { |
86 render_view->Send(new BrowserPluginHostMsg_NavigateFromEmbedder( | 86 render_view->Send(new BrowserPluginHostMsg_NavigateFromEmbedder( |
87 render_view->GetRoutingID(), | 87 render_view->GetRoutingID(), |
88 id_, | 88 id_, |
89 frame->identifier(), | 89 frame->identifier(), |
90 src, | 90 src)); |
91 size)); | |
92 } | 91 } |
93 } | 92 } |
94 | 93 |
95 BrowserPlugin::~BrowserPlugin() { | 94 BrowserPlugin::~BrowserPlugin() { |
96 Unregister(id_); | 95 Unregister(id_); |
97 } | 96 } |
98 | 97 |
99 void BrowserPlugin::ParsePluginParameters( | 98 void BrowserPlugin::ParseSrcAttribute( |
100 int default_width, | |
101 int default_height, | |
102 const std::string& default_src, | 99 const std::string& default_src, |
103 gfx::Size* size, | |
104 std::string* src) { | 100 std::string* src) { |
105 int width = default_width; | 101 // Get the src attribute from the attributes vector |
106 int height = default_height; | |
107 | |
108 // Get the plugin parameters from the attributes vector | |
109 for (unsigned i = 0; i < plugin_params_.attributeNames.size(); ++i) { | 102 for (unsigned i = 0; i < plugin_params_.attributeNames.size(); ++i) { |
110 std::string attributeName = plugin_params_.attributeNames[i].utf8(); | 103 std::string attributeName = plugin_params_.attributeNames[i].utf8(); |
111 if (LowerCaseEqualsASCII(attributeName, "width")) { | 104 if (LowerCaseEqualsASCII(attributeName, "src")) { |
112 std::string attributeValue = plugin_params_.attributeValues[i].utf8(); | |
113 CHECK(base::StringToInt(attributeValue, &width)); | |
114 } else if (LowerCaseEqualsASCII(attributeName, "height")) { | |
115 std::string attributeValue = plugin_params_.attributeValues[i].utf8(); | |
116 CHECK(base::StringToInt(attributeValue, &height)); | |
117 } else if (LowerCaseEqualsASCII(attributeName, "src")) { | |
118 *src = plugin_params_.attributeValues[i].utf8(); | 105 *src = plugin_params_.attributeValues[i].utf8(); |
106 break; | |
119 } | 107 } |
120 } | 108 } |
121 // If we didn't find the attributes set or they're not sensible, | 109 // If we didn't find the attributes set or they're not sensible, |
122 // we reset our attributes to the default. | 110 // we reset our attributes to the default. |
123 if (src->empty()) { | 111 if (src->empty()) { |
124 *src = default_src; | 112 *src = default_src; |
125 } | 113 } |
126 | |
127 size->SetSize(width, height); | |
128 } | 114 } |
129 | 115 |
130 void BrowserPlugin::LoadGuest( | 116 void BrowserPlugin::LoadGuest( |
131 int guest_process_id, | 117 int guest_process_id, |
132 const IPC::ChannelHandle& channel_handle) { | 118 const IPC::ChannelHandle& channel_handle) { |
133 webkit::ppapi::WebPluginImpl* new_guest = | 119 webkit::ppapi::WebPluginImpl* new_guest = |
134 render_view()->CreateBrowserPlugin(channel_handle, | 120 render_view()->CreateBrowserPlugin(channel_handle, |
135 guest_process_id, | 121 guest_process_id, |
136 plugin_params()); | 122 plugin_params()); |
137 Replace(new_guest); | 123 Replace(new_guest); |
138 } | 124 } |
139 | 125 |
140 void BrowserPlugin::Replace( | 126 void BrowserPlugin::Replace( |
141 webkit::ppapi::WebPluginImpl* new_plugin) { | 127 webkit::ppapi::WebPluginImpl* new_plugin) { |
142 WebKit::WebPlugin* current_plugin = | 128 WebKit::WebPlugin* current_plugin = |
143 plugin_ ? static_cast<WebKit::WebPlugin*>(plugin_) : placeholder_; | 129 plugin_ ? static_cast<WebKit::WebPlugin*>(plugin_) : placeholder_; |
144 WebKit::WebPluginContainer* container = current_plugin->container(); | 130 WebKit::WebPluginContainer* container = current_plugin->container(); |
145 if (!new_plugin || !new_plugin->initialize(container)) | 131 if (!new_plugin || !new_plugin->initialize(container)) |
146 return; | 132 return; |
147 | 133 |
148 // Clear the container's backing texture ID and the script objects. | 134 // Clear the container's backing texture ID and the script objects. |
149 if (plugin_) | 135 if (plugin_) |
150 plugin_->instance()->BindGraphics(plugin_->instance()->pp_instance(), 0); | 136 plugin_->instance()->BindGraphics(plugin_->instance()->pp_instance(), 0); |
151 | 137 |
152 // Inform the browser process of the association between the browser plugin's | 138 PP_Instance instance = new_plugin->instance()->pp_instance(); |
153 // instance ID and the pepper channel's PP_Instance identifier. | 139 ppapi::proxy::HostDispatcher* dispatcher = |
154 render_view()->Send(new BrowserPluginHostMsg_MapInstance( | 140 ppapi::proxy::HostDispatcher::GetForInstance(instance); |
155 render_view()->GetRoutingID(), | 141 DCHECK(dispatcher); |
jam
2012/05/23 22:11:10
nit: skip this dcheck, it's unnecessary
Fady Samuel
2012/05/23 22:23:43
Done.
| |
156 id_, | 142 dispatcher->Send(new BrowserPluginMsg_GuestReady(instance, id_)); |
157 new_plugin->instance()->pp_instance())); | 143 |
158 // TODO(fsamuel): We should delay the swapping out of the current plugin | 144 // TODO(fsamuel): We should delay the swapping out of the current plugin |
159 // until after the guest's WebGraphicsContext3D has been initialized. That | 145 // until after the guest's WebGraphicsContext3D has been initialized. That |
160 // way, we immediately have something to render onto the screen. | 146 // way, we immediately have something to render onto the screen. |
161 container->setPlugin(new_plugin); | 147 container->setPlugin(new_plugin); |
162 container->invalidate(); | 148 container->invalidate(); |
163 container->reportGeometry(); | 149 container->reportGeometry(); |
164 if (plugin_) | 150 if (plugin_) |
165 plugin_->destroy(); | 151 plugin_->destroy(); |
166 plugin_ = new_plugin; | 152 plugin_ = new_plugin; |
167 } | 153 } |
OLD | NEW |