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 #if defined (OS_WIN) | 9 #if defined (OS_WIN) |
10 #include "base/sys_info.h" | 10 #include "base/sys_info.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 : instance_id_(instance_id), | 65 : instance_id_(instance_id), |
66 render_view_(render_view), | 66 render_view_(render_view), |
67 container_(NULL), | 67 container_(NULL), |
68 damage_buffer_(NULL), | 68 damage_buffer_(NULL), |
69 sad_guest_(NULL), | 69 sad_guest_(NULL), |
70 guest_crashed_(false), | 70 guest_crashed_(false), |
71 resize_pending_(false), | 71 resize_pending_(false), |
72 navigate_src_sent_(false), | 72 navigate_src_sent_(false), |
73 process_id_(-1), | 73 process_id_(-1), |
74 persist_storage_(false), | 74 persist_storage_(false), |
75 visible_(true) { | 75 visible_(true), |
| 76 current_nav_entry_index_(0), |
| 77 nav_entry_count_(0) { |
76 BrowserPluginManager::Get()->AddBrowserPlugin(instance_id, this); | 78 BrowserPluginManager::Get()->AddBrowserPlugin(instance_id, this); |
77 bindings_.reset(new BrowserPluginBindings(this)); | 79 bindings_.reset(new BrowserPluginBindings(this)); |
78 | 80 |
79 ParseAttributes(params); | 81 ParseAttributes(params); |
80 } | 82 } |
81 | 83 |
82 BrowserPlugin::~BrowserPlugin() { | 84 BrowserPlugin::~BrowserPlugin() { |
83 if (damage_buffer_) | 85 if (damage_buffer_) |
84 FreeDamageBuffer(); | 86 FreeDamageBuffer(); |
85 RemoveEventListeners(); | 87 RemoveEventListeners(); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 | 144 |
143 std::string BrowserPlugin::GetPartitionAttribute() const { | 145 std::string BrowserPlugin::GetPartitionAttribute() const { |
144 std::string value; | 146 std::string value; |
145 if (persist_storage_) | 147 if (persist_storage_) |
146 value.append(kPersistPrefix); | 148 value.append(kPersistPrefix); |
147 | 149 |
148 value.append(storage_partition_id_); | 150 value.append(storage_partition_id_); |
149 return value; | 151 return value; |
150 } | 152 } |
151 | 153 |
| 154 bool BrowserPlugin::CanGoBack() const { |
| 155 return nav_entry_count_ > 1 && current_nav_entry_index_ > 0; |
| 156 } |
| 157 |
| 158 bool BrowserPlugin::CanGoForward() const { |
| 159 return current_nav_entry_index_ >= 0 && |
| 160 current_nav_entry_index_ < (nav_entry_count_ - 1); |
| 161 } |
| 162 |
152 bool BrowserPlugin::SetPartitionAttribute(const std::string& partition_id, | 163 bool BrowserPlugin::SetPartitionAttribute(const std::string& partition_id, |
153 std::string& error_message) { | 164 std::string& error_message) { |
154 if (navigate_src_sent_) { | 165 if (navigate_src_sent_) { |
155 error_message = | 166 error_message = |
156 "The object has already navigated, so its partition cannot be changed."; | 167 "The object has already navigated, so its partition cannot be changed."; |
157 return false; | 168 return false; |
158 } | 169 } |
159 | 170 |
160 std::string input = partition_id; | 171 std::string input = partition_id; |
161 | 172 |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 // called. See http://crbug.com/155044. | 345 // called. See http://crbug.com/155044. |
335 EventListeners listeners(event_listener_map_[kCrashEventName]); | 346 EventListeners listeners(event_listener_map_[kCrashEventName]); |
336 EventListeners::iterator it = listeners.begin(); | 347 EventListeners::iterator it = listeners.begin(); |
337 for (; it != listeners.end(); ++it) { | 348 for (; it != listeners.end(); ++it) { |
338 WebKit::WebFrame* frame = plugin.document().frame(); | 349 WebKit::WebFrame* frame = plugin.document().frame(); |
339 if (frame) | 350 if (frame) |
340 frame->callFunctionEvenIfScriptDisabled(*it, v8::Object::New(), 0, NULL); | 351 frame->callFunctionEvenIfScriptDisabled(*it, v8::Object::New(), 0, NULL); |
341 } | 352 } |
342 } | 353 } |
343 | 354 |
344 void BrowserPlugin::DidNavigate(const GURL& url, int process_id) { | 355 void BrowserPlugin::DidNavigate( |
345 src_ = url.spec(); | 356 const BrowserPluginMsg_DidNavigate_Params& params) { |
346 process_id_ = process_id; | 357 src_ = params.url.spec(); |
| 358 process_id_ = params.process_id; |
| 359 current_nav_entry_index_ = params.current_entry_index; |
| 360 nav_entry_count_ = params.entry_count; |
| 361 |
347 if (!HasListeners(kNavigationEventName)) | 362 if (!HasListeners(kNavigationEventName)) |
348 return; | 363 return; |
349 | 364 |
350 WebKit::WebElement plugin = container()->element(); | 365 WebKit::WebElement plugin = container()->element(); |
351 v8::HandleScope handle_scope; | 366 v8::HandleScope handle_scope; |
352 v8::Context::Scope context_scope( | 367 v8::Context::Scope context_scope( |
353 plugin.document().frame()->mainWorldScriptContext()); | 368 plugin.document().frame()->mainWorldScriptContext()); |
354 | 369 |
355 v8::Local<v8::Value> param = v8::String::New(src_.data(), src_.size()); | 370 // Construct the navigation event object. |
| 371 v8::Local<v8::Object> event = v8::Object::New(); |
| 372 event->Set(v8::String::New(kURL, sizeof(kURL) - 1), |
| 373 v8::String::New(src_.data(), src_.size())); |
| 374 event->Set(v8::String::New(kIsTopLevel, sizeof(kIsTopLevel) - 1), |
| 375 v8::Boolean::New(params.is_top_level)); |
| 376 v8::Local<v8::Value> val = event; |
356 | 377 |
357 // TODO(fsamuel): Copying the event listeners is insufficent because | 378 // TODO(fsamuel): Copying the event listeners is insufficent because |
358 // new persistent handles are not created when the copy constructor is | 379 // new persistent handles are not created when the copy constructor is |
359 // called. See http://crbug.com/155044. | 380 // called. See http://crbug.com/155044. |
360 EventListeners listeners(event_listener_map_[kNavigationEventName]); | 381 EventListeners listeners(event_listener_map_[kNavigationEventName]); |
361 EventListeners::iterator it = listeners.begin(); | 382 EventListeners::iterator it = listeners.begin(); |
362 for (; it != listeners.end(); ++it) { | 383 for (; it != listeners.end(); ++it) { |
363 WebKit::WebFrame* frame = plugin.document().frame(); | 384 WebKit::WebFrame* frame = plugin.document().frame(); |
364 if (frame) { | 385 if (frame) { |
365 frame->callFunctionEvenIfScriptDisabled( | 386 frame->callFunctionEvenIfScriptDisabled( |
366 *it, v8::Object::New(), 1, ¶m); | 387 *it, v8::Object::New(), 1, &val); |
367 } | 388 } |
368 } | 389 } |
369 } | 390 } |
370 | 391 |
371 void BrowserPlugin::LoadStart(const GURL& url, bool is_top_level) { | 392 void BrowserPlugin::LoadStart(const GURL& url, bool is_top_level) { |
372 if (!HasListeners(kLoadStartEventName)) | 393 if (!HasListeners(kLoadStartEventName)) |
373 return; | 394 return; |
374 | 395 |
375 WebKit::WebElement plugin = container()->element(); | 396 WebKit::WebElement plugin = container()->element(); |
376 v8::HandleScope handle_scope; | 397 v8::HandleScope handle_scope; |
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
750 void* notify_data) { | 771 void* notify_data) { |
751 } | 772 } |
752 | 773 |
753 void BrowserPlugin::didFailLoadingFrameRequest( | 774 void BrowserPlugin::didFailLoadingFrameRequest( |
754 const WebKit::WebURL& url, | 775 const WebKit::WebURL& url, |
755 void* notify_data, | 776 void* notify_data, |
756 const WebKit::WebURLError& error) { | 777 const WebKit::WebURLError& error) { |
757 } | 778 } |
758 | 779 |
759 } // namespace content | 780 } // namespace content |
OLD | NEW |