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 24 matching lines...) Expand all Loading... |
35 using WebKit::WebPluginParams; | 35 using WebKit::WebPluginParams; |
36 using WebKit::WebPoint; | 36 using WebKit::WebPoint; |
37 using WebKit::WebString; | 37 using WebKit::WebString; |
38 using WebKit::WebRect; | 38 using WebKit::WebRect; |
39 using WebKit::WebURL; | 39 using WebKit::WebURL; |
40 using WebKit::WebVector; | 40 using WebKit::WebVector; |
41 | 41 |
42 namespace content { | 42 namespace content { |
43 | 43 |
44 namespace { | 44 namespace { |
| 45 |
| 46 // Adding a new event? Update InitializeEvents as well. |
45 const char kExitEventName[] = "exit"; | 47 const char kExitEventName[] = "exit"; |
46 const char kIsTopLevel[] = "isTopLevel"; | 48 const char kIsTopLevel[] = "isTopLevel"; |
47 const char kLoadAbortEventName[] = "loadabort"; | 49 const char kLoadAbortEventName[] = "loadabort"; |
48 const char kLoadCommitEventName[] = "loadcommit"; | 50 const char kLoadCommitEventName[] = "loadcommit"; |
49 const char kLoadRedirectEventName[] = "loadredirect"; | 51 const char kLoadRedirectEventName[] = "loadredirect"; |
50 const char kLoadStartEventName[] = "loadstart"; | 52 const char kLoadStartEventName[] = "loadstart"; |
51 const char kLoadStopEventName[] = "loadstop"; | 53 const char kLoadStopEventName[] = "loadstop"; |
| 54 const char kTitleChangeEventName[] = "titlechange"; |
| 55 |
52 const char kNewURL[] = "newUrl"; | 56 const char kNewURL[] = "newUrl"; |
53 const char kOldURL[] = "oldUrl"; | 57 const char kOldURL[] = "oldUrl"; |
54 const char kPartitionAttribute[] = "partition"; | 58 const char kPartitionAttribute[] = "partition"; |
55 const char kPersistPrefix[] = "persist:"; | 59 const char kPersistPrefix[] = "persist:"; |
56 const char kProcessId[] = "processId"; | 60 const char kProcessId[] = "processId"; |
57 const char kSrcAttribute[] = "src"; | 61 const char kSrcAttribute[] = "src"; |
| 62 const char kTitle[] = "title"; |
58 const char kType[] = "type"; | 63 const char kType[] = "type"; |
59 const char kURL[] = "url"; | 64 const char kURL[] = "url"; |
60 | 65 |
61 static std::string TerminationStatusToString(base::TerminationStatus status) { | 66 static std::string TerminationStatusToString(base::TerminationStatus status) { |
62 switch (status) { | 67 switch (status) { |
63 case base::TERMINATION_STATUS_NORMAL_TERMINATION: | 68 case base::TERMINATION_STATUS_NORMAL_TERMINATION: |
64 return "normal"; | 69 return "normal"; |
65 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION: | 70 case base::TERMINATION_STATUS_ABNORMAL_TERMINATION: |
66 return "abnormal"; | 71 return "abnormal"; |
67 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: | 72 case base::TERMINATION_STATUS_PROCESS_WAS_KILLED: |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 return render_view_->GetWebView()->deviceScaleFactor(); | 251 return render_view_->GetWebView()->deviceScaleFactor(); |
247 } | 252 } |
248 | 253 |
249 void BrowserPlugin::InitializeEvents() { | 254 void BrowserPlugin::InitializeEvents() { |
250 event_listener_map_[kExitEventName] = EventListeners(); | 255 event_listener_map_[kExitEventName] = EventListeners(); |
251 event_listener_map_[kLoadAbortEventName] = EventListeners(); | 256 event_listener_map_[kLoadAbortEventName] = EventListeners(); |
252 event_listener_map_[kLoadCommitEventName] = EventListeners(); | 257 event_listener_map_[kLoadCommitEventName] = EventListeners(); |
253 event_listener_map_[kLoadRedirectEventName] = EventListeners(); | 258 event_listener_map_[kLoadRedirectEventName] = EventListeners(); |
254 event_listener_map_[kLoadStartEventName] = EventListeners(); | 259 event_listener_map_[kLoadStartEventName] = EventListeners(); |
255 event_listener_map_[kLoadStopEventName] = EventListeners(); | 260 event_listener_map_[kLoadStopEventName] = EventListeners(); |
| 261 event_listener_map_[kTitleChangeEventName] = EventListeners(); |
256 } | 262 } |
257 | 263 |
258 void BrowserPlugin::RemoveEventListeners() { | 264 void BrowserPlugin::RemoveEventListeners() { |
259 EventListenerMap::iterator event_listener_map_iter = | 265 EventListenerMap::iterator event_listener_map_iter = |
260 event_listener_map_.begin(); | 266 event_listener_map_.begin(); |
261 for (; event_listener_map_iter != event_listener_map_.end(); | 267 for (; event_listener_map_iter != event_listener_map_.end(); |
262 ++event_listener_map_iter) { | 268 ++event_listener_map_iter) { |
263 EventListeners& listeners = | 269 EventListeners& listeners = |
264 event_listener_map_[event_listener_map_iter->first]; | 270 event_listener_map_[event_listener_map_iter->first]; |
265 EventListeners::iterator it = listeners.begin(); | 271 EventListeners::iterator it = listeners.begin(); |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 event->Set(v8::String::New(kNewURL, sizeof(kNewURL) - 1), | 558 event->Set(v8::String::New(kNewURL, sizeof(kNewURL) - 1), |
553 v8::String::New(new_url.spec().data(), new_url.spec().size()), | 559 v8::String::New(new_url.spec().data(), new_url.spec().size()), |
554 v8::ReadOnly); | 560 v8::ReadOnly); |
555 event->Set(v8::String::New(kIsTopLevel, sizeof(kIsTopLevel) - 1), | 561 event->Set(v8::String::New(kIsTopLevel, sizeof(kIsTopLevel) - 1), |
556 v8::Boolean::New(is_top_level), | 562 v8::Boolean::New(is_top_level), |
557 v8::ReadOnly); | 563 v8::ReadOnly); |
558 | 564 |
559 TriggerEvent(kLoadRedirectEventName, &event); | 565 TriggerEvent(kLoadRedirectEventName, &event); |
560 } | 566 } |
561 | 567 |
| 568 void BrowserPlugin::TitleChange(const string16& title) { |
| 569 if (!HasListeners(kTitleChangeEventName)) |
| 570 return; |
| 571 |
| 572 WebKit::WebElement plugin = container()->element(); |
| 573 v8::HandleScope handle_scope; |
| 574 v8::Context::Scope context_scope( |
| 575 plugin.document().frame()->mainWorldScriptContext()); |
| 576 |
| 577 // Construct the titlechanged event object. |
| 578 v8::Local<v8::Object> event = v8::Object::New(); |
| 579 event->Set(v8::String::New(kTitle, sizeof(kTitle) - 1), |
| 580 v8::String::New(title.data(), title.size()), |
| 581 v8::ReadOnly); |
| 582 |
| 583 TriggerEvent(kTitleChangeEventName, &event); |
| 584 } |
| 585 |
562 void BrowserPlugin::AdvanceFocus(bool reverse) { | 586 void BrowserPlugin::AdvanceFocus(bool reverse) { |
563 // We do not have a RenderView when we are testing. | 587 // We do not have a RenderView when we are testing. |
564 if (render_view_) | 588 if (render_view_) |
565 render_view_->GetWebView()->advanceFocus(reverse); | 589 render_view_->GetWebView()->advanceFocus(reverse); |
566 } | 590 } |
567 | 591 |
568 void BrowserPlugin::GuestContentWindowReady(int content_window_routing_id) { | 592 void BrowserPlugin::GuestContentWindowReady(int content_window_routing_id) { |
569 DCHECK(content_window_routing_id != MSG_ROUTING_NONE); | 593 DCHECK(content_window_routing_id != MSG_ROUTING_NONE); |
570 content_window_routing_id_ = content_window_routing_id; | 594 content_window_routing_id_ = content_window_routing_id; |
571 } | 595 } |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
890 void* notify_data) { | 914 void* notify_data) { |
891 } | 915 } |
892 | 916 |
893 void BrowserPlugin::didFailLoadingFrameRequest( | 917 void BrowserPlugin::didFailLoadingFrameRequest( |
894 const WebKit::WebURL& url, | 918 const WebKit::WebURL& url, |
895 void* notify_data, | 919 void* notify_data, |
896 const WebKit::WebURLError& error) { | 920 const WebKit::WebURLError& error) { |
897 } | 921 } |
898 | 922 |
899 } // namespace content | 923 } // namespace content |
OLD | NEW |