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 "content/common/browser_plugin_messages.h" | 9 #include "content/common/browser_plugin_messages.h" |
10 #include "content/public/common/content_client.h" | 10 #include "content/public/common/content_client.h" |
(...skipping 22 matching lines...) Expand all Loading... | |
33 using WebKit::WebRect; | 33 using WebKit::WebRect; |
34 using WebKit::WebURL; | 34 using WebKit::WebURL; |
35 using WebKit::WebVector; | 35 using WebKit::WebVector; |
36 | 36 |
37 namespace content { | 37 namespace content { |
38 | 38 |
39 namespace { | 39 namespace { |
40 const char kCrashEventName[] = "crash"; | 40 const char kCrashEventName[] = "crash"; |
41 const char kNavigationEventName[] = "navigation"; | 41 const char kNavigationEventName[] = "navigation"; |
42 const char* kSrcAttribute = "src"; | 42 const char* kSrcAttribute = "src"; |
43 const char kPartitionAttribute[] = "partition"; | |
44 const char kPersistAttribute[] = "persist"; | |
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_(UNSET_VALUE) { | |
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 return partition_id_; |
107 std::string* src) { | 110 } |
108 // Get the src attribute from the attributes vector | 111 |
112 bool BrowserPlugin::SetPartitionAttribute(const std::string& partition_id) { | |
113 if (has_navigated_ || !partition_id_.empty()) | |
michaeln
2012/09/10 23:01:43
is there a reason to prevent setting to a differen
nasko
2012/09/10 23:16:08
We want to alert the developers that this is a one
| |
114 return false; | |
115 | |
116 partition_id_ = partition_id; | |
117 return true; | |
118 } | |
119 | |
120 bool BrowserPlugin::GetPersistAttribute() const { | |
121 if (persist_storage_ == TRUE_VALUE) | |
122 return true; | |
123 | |
124 return false; | |
125 } | |
126 | |
127 bool BrowserPlugin::SetPersistAttribute(bool persist) { | |
128 if (has_navigated_ || persist_storage_ != UNSET_VALUE) | |
129 return false; | |
130 | |
131 persist_storage_ = persist ? TRUE_VALUE : FALSE_VALUE; | |
132 return true; | |
133 } | |
134 | |
135 void BrowserPlugin::ParseAttributes(const WebKit::WebPluginParams& params) { | |
136 std::string src; | |
109 for (unsigned i = 0; i < params.attributeNames.size(); ++i) { | 137 for (unsigned i = 0; i < params.attributeNames.size(); ++i) { |
110 std::string attributeName = params.attributeNames[i].utf8(); | 138 std::string attributeName = params.attributeNames[i].utf8(); |
111 if (LowerCaseEqualsASCII(attributeName, kSrcAttribute)) { | 139 if (LowerCaseEqualsASCII(attributeName, kSrcAttribute)) { |
112 *src = params.attributeValues[i].utf8(); | 140 src = params.attributeValues[i].utf8(); |
113 return true; | 141 } else if (LowerCaseEqualsASCII(attributeName, kPartitionAttribute)) { |
142 SetPartitionAttribute(params.attributeValues[i].utf8()); | |
143 } else if (LowerCaseEqualsASCII(attributeName, kPersistAttribute)) { | |
144 SetPersistAttribute(true); | |
114 } | 145 } |
115 } | 146 } |
116 return false; | 147 // Set the 'src' attribute last, as it will set the has_navigated_ flag to |
148 // true, which prevents changing the 'partition' and 'persist' attributes. | |
149 if (!src.empty()) | |
150 SetSrcAttribute(src); | |
117 } | 151 } |
118 | 152 |
119 float BrowserPlugin::GetDeviceScaleFactor() const { | 153 float BrowserPlugin::GetDeviceScaleFactor() const { |
120 if (!render_view_) | 154 if (!render_view_) |
121 return 1.0f; | 155 return 1.0f; |
122 return render_view_->GetWebView()->deviceScaleFactor(); | 156 return render_view_->GetWebView()->deviceScaleFactor(); |
123 } | 157 } |
124 | 158 |
125 void BrowserPlugin::RemoveEventListeners() { | 159 void BrowserPlugin::RemoveEventListeners() { |
126 EventListenerMap::iterator event_listener_map_iter = | 160 EventListenerMap::iterator event_listener_map_iter = |
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
412 void* notify_data) { | 446 void* notify_data) { |
413 } | 447 } |
414 | 448 |
415 void BrowserPlugin::didFailLoadingFrameRequest( | 449 void BrowserPlugin::didFailLoadingFrameRequest( |
416 const WebKit::WebURL& url, | 450 const WebKit::WebURL& url, |
417 void* notify_data, | 451 void* notify_data, |
418 const WebKit::WebURLError& error) { | 452 const WebKit::WebURLError& error) { |
419 } | 453 } |
420 | 454 |
421 } // namespace content | 455 } // namespace content |
OLD | NEW |