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/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/utf_string_conversions.h" | |
9 #include "content/common/browser_plugin_messages.h" | 10 #include "content/common/browser_plugin_messages.h" |
10 #include "content/public/common/content_client.h" | 11 #include "content/public/common/content_client.h" |
11 #include "content/public/renderer/content_renderer_client.h" | 12 #include "content/public/renderer/content_renderer_client.h" |
12 #include "content/renderer/browser_plugin/browser_plugin_bindings.h" | 13 #include "content/renderer/browser_plugin/browser_plugin_bindings.h" |
13 #include "content/renderer/browser_plugin/browser_plugin_manager.h" | 14 #include "content/renderer/browser_plugin/browser_plugin_manager.h" |
14 #include "content/renderer/render_process_impl.h" | 15 #include "content/renderer/render_process_impl.h" |
15 #include "content/renderer/render_thread_impl.h" | 16 #include "content/renderer/render_thread_impl.h" |
16 #include "skia/ext/platform_canvas.h" | 17 #include "skia/ext/platform_canvas.h" |
17 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h" |
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
(...skipping 14 matching lines...) Expand all Loading... | |
33 using WebKit::WebRect; | 34 using WebKit::WebRect; |
34 using WebKit::WebURL; | 35 using WebKit::WebURL; |
35 using WebKit::WebVector; | 36 using WebKit::WebVector; |
36 | 37 |
37 namespace content { | 38 namespace content { |
38 | 39 |
39 namespace { | 40 namespace { |
40 const char kCrashEventName[] = "crash"; | 41 const char kCrashEventName[] = "crash"; |
41 const char kNavigationEventName[] = "navigation"; | 42 const char kNavigationEventName[] = "navigation"; |
42 const char* kSrcAttribute = "src"; | 43 const char* kSrcAttribute = "src"; |
44 const char* kPartitionAttribute = "partition"; | |
43 } | 45 } |
44 | 46 |
45 BrowserPlugin::BrowserPlugin( | 47 BrowserPlugin::BrowserPlugin( |
46 int instance_id, | 48 int instance_id, |
47 RenderViewImpl* render_view, | 49 RenderViewImpl* render_view, |
48 WebKit::WebFrame* frame, | 50 WebKit::WebFrame* frame, |
49 const WebPluginParams& params) | 51 const WebPluginParams& params) |
50 : instance_id_(instance_id), | 52 : instance_id_(instance_id), |
51 render_view_(render_view), | 53 render_view_(render_view), |
52 container_(NULL), | 54 container_(NULL), |
53 damage_buffer_(NULL), | 55 damage_buffer_(NULL), |
54 sad_guest_(NULL), | 56 sad_guest_(NULL), |
55 guest_crashed_(false), | 57 guest_crashed_(false), |
56 resize_pending_(false), | 58 resize_pending_(false), |
57 parent_frame_(frame->identifier()) { | 59 parent_frame_(frame->identifier()), |
60 has_navigated_(false), | |
61 persist_storage_(false) { | |
58 BrowserPluginManager::Get()->AddBrowserPlugin(instance_id, this); | 62 BrowserPluginManager::Get()->AddBrowserPlugin(instance_id, this); |
59 bindings_.reset(new BrowserPluginBindings(this)); | 63 bindings_.reset(new BrowserPluginBindings(this)); |
60 | 64 |
61 std::string src; | 65 ParseAttributes(params); |
62 if (ParseSrcAttribute(params, &src)) | |
63 SetSrcAttribute(src); | |
64 } | 66 } |
65 | 67 |
66 BrowserPlugin::~BrowserPlugin() { | 68 BrowserPlugin::~BrowserPlugin() { |
67 if (damage_buffer_) { | 69 if (damage_buffer_) { |
68 RenderProcess::current()->FreeTransportDIB(damage_buffer_); | 70 RenderProcess::current()->FreeTransportDIB(damage_buffer_); |
69 damage_buffer_ = NULL; | 71 damage_buffer_ = NULL; |
70 } | 72 } |
71 RemoveEventListeners(); | 73 RemoveEventListeners(); |
72 BrowserPluginManager::Get()->RemoveBrowserPlugin(instance_id_); | 74 BrowserPluginManager::Get()->RemoveBrowserPlugin(instance_id_); |
73 BrowserPluginManager::Get()->Send( | 75 BrowserPluginManager::Get()->Send( |
(...skipping 16 matching lines...) Expand all Loading... | |
90 void BrowserPlugin::SetSrcAttribute(const std::string& src) { | 92 void BrowserPlugin::SetSrcAttribute(const std::string& src) { |
91 if (src == src_ && !guest_crashed_) | 93 if (src == src_ && !guest_crashed_) |
92 return; | 94 return; |
93 if (!src.empty()) { | 95 if (!src.empty()) { |
94 BrowserPluginManager::Get()->Send( | 96 BrowserPluginManager::Get()->Send( |
95 new BrowserPluginHostMsg_NavigateOrCreateGuest( | 97 new BrowserPluginHostMsg_NavigateOrCreateGuest( |
96 render_view_->GetRoutingID(), | 98 render_view_->GetRoutingID(), |
97 instance_id_, | 99 instance_id_, |
98 parent_frame_, | 100 parent_frame_, |
99 src)); | 101 src)); |
102 has_navigated_ = true; | |
100 } | 103 } |
101 src_ = src; | 104 src_ = src; |
102 guest_crashed_ = false; | 105 guest_crashed_ = false; |
103 } | 106 } |
104 | 107 |
105 bool BrowserPlugin::ParseSrcAttribute( | 108 std::string BrowserPlugin::GetPartitionAttribute() const { |
106 const WebKit::WebPluginParams& params, | 109 std::string value; |
107 std::string* src) { | 110 if (persist_storage_) |
111 value.append("persist:"); | |
Charlie Reis
2012/09/18 22:09:33
This should be a constant at the top of the file.
nasko
2012/09/18 22:56:20
Done.
| |
112 | |
113 value.append(storage_partition_id_); | |
114 return value; | |
115 } | |
116 | |
117 bool BrowserPlugin::SetPartitionAttribute(const std::string& partition_id, | |
118 std::string& error_message) { | |
119 if (has_navigated_) { | |
120 error_message = "The object has already navigated."; | |
Charlie Reis
2012/09/18 22:09:33
Can we provide a little more to help the developer
nasko
2012/09/18 22:56:20
Done.
| |
121 return false; | |
122 } | |
123 if (!storage_partition_id_.empty()) { | |
124 error_message = "The partition attribute has already been set."; | |
Charlie Reis
2012/09/18 22:09:33
Why is this an error? Couldn't you safely set it
nasko
2012/09/18 22:56:20
I would like to disallow setting it multiple times
Charlie Reis
2012/09/19 00:06:31
That seems like an unnecessary restriction to me,
nasko
2012/09/19 17:03:23
Done.
| |
125 return false; | |
126 } | |
127 | |
128 std::string input = partition_id; | |
129 std::string persist_prefix("persist:"); | |
130 | |
131 // Since the "persist:" prefix is in ASCII, StartsWith will work fine on | |
132 // UTF-8 encoded |partition_id|. If the prefix is a match, we can safely | |
133 // remove the prefix without splicing in the middle of a multi-byte codepoint. | |
134 // We can use the rest of the string as UTF-8 encoded one. | |
Charlie Reis
2012/09/18 22:09:33
Awesome comment.
nasko
2012/09/18 22:56:20
Credit goes to the master of awesomeness - ajwong!
| |
135 if (StartsWithASCII(input, persist_prefix, true)) { | |
136 size_t index = input.find(":"); | |
137 CHECK(index != std::string::npos); | |
138 // It is safe to do index + 1, since we tested for the full prefix above. | |
139 input = input.substr(index + 1); | |
140 if (input.empty()) { | |
141 error_message = "Invalid partition attribute."; | |
Charlie Reis
2012/09/18 22:09:33
Maybe "Invalid empty partition attribute"? This i
nasko
2012/09/18 22:56:20
Done.
| |
142 return false; | |
143 } | |
144 persist_storage_ = true; | |
145 } else { | |
146 persist_storage_ = false; | |
147 } | |
148 | |
149 storage_partition_id_ = input; | |
150 return true; | |
151 } | |
152 | |
153 void BrowserPlugin::ParseAttributes(const WebKit::WebPluginParams& params) { | |
154 std::string src; | |
155 | |
108 // Get the src attribute from the attributes vector | 156 // Get the src attribute from the attributes vector |
109 for (unsigned i = 0; i < params.attributeNames.size(); ++i) { | 157 for (unsigned i = 0; i < params.attributeNames.size(); ++i) { |
110 std::string attributeName = params.attributeNames[i].utf8(); | 158 std::string attributeName = params.attributeNames[i].utf8(); |
111 if (LowerCaseEqualsASCII(attributeName, kSrcAttribute)) { | 159 if (LowerCaseEqualsASCII(attributeName, kSrcAttribute)) { |
112 *src = params.attributeValues[i].utf8(); | 160 src = params.attributeValues[i].utf8(); |
113 return true; | 161 } else if (LowerCaseEqualsASCII(attributeName, kPartitionAttribute)) { |
162 std::string error; | |
163 SetPartitionAttribute(params.attributeValues[i].utf8(), error); | |
114 } | 164 } |
115 } | 165 } |
116 return false; | 166 |
167 // Set the 'src' attribute last, as it will set the has_navigated_ flag to | |
168 // true, which prevents changing the 'partition' attribute. | |
Charlie Reis
2012/09/18 22:09:33
Ah, good point.
nasko
2012/09/18 22:56:20
Done.
| |
169 if (!src.empty()) | |
170 SetSrcAttribute(src); | |
117 } | 171 } |
118 | 172 |
119 float BrowserPlugin::GetDeviceScaleFactor() const { | 173 float BrowserPlugin::GetDeviceScaleFactor() const { |
120 if (!render_view_) | 174 if (!render_view_) |
121 return 1.0f; | 175 return 1.0f; |
122 return render_view_->GetWebView()->deviceScaleFactor(); | 176 return render_view_->GetWebView()->deviceScaleFactor(); |
123 } | 177 } |
124 | 178 |
125 void BrowserPlugin::RemoveEventListeners() { | 179 void BrowserPlugin::RemoveEventListeners() { |
126 EventListenerMap::iterator event_listener_map_iter = | 180 EventListenerMap::iterator event_listener_map_iter = |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
412 void* notify_data) { | 466 void* notify_data) { |
413 } | 467 } |
414 | 468 |
415 void BrowserPlugin::didFailLoadingFrameRequest( | 469 void BrowserPlugin::didFailLoadingFrameRequest( |
416 const WebKit::WebURL& url, | 470 const WebKit::WebURL& url, |
417 void* notify_data, | 471 void* notify_data, |
418 const WebKit::WebURLError& error) { | 472 const WebKit::WebURLError& error) { |
419 } | 473 } |
420 | 474 |
421 } // namespace content | 475 } // namespace content |
OLD | NEW |