| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/browser/intents/intent_injector.h" | 5 #include "content/browser/intents/intent_injector.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/string16.h" | 9 #include "base/string16.h" |
| 10 #include "content/browser/renderer_host/render_view_host.h" | 10 #include "content/browser/renderer_host/render_view_host.h" |
| 11 #include "content/browser/tab_contents/tab_contents.h" | 11 #include "content/browser/tab_contents/tab_contents.h" |
| 12 #include "content/common/intents_messages.h" | 12 #include "content/common/intents_messages.h" |
| 13 #include "content/public/browser/intents_host.h" | 13 #include "content/public/browser/web_intents_dispatcher.h" |
| 14 #include "content/public/common/content_switches.h" | 14 #include "content/public/common/content_switches.h" |
| 15 #include "webkit/glue/web_intent_data.h" | 15 #include "webkit/glue/web_intent_data.h" |
| 16 #include "webkit/glue/web_intent_reply_data.h" | 16 #include "webkit/glue/web_intent_reply_data.h" |
| 17 | 17 |
| 18 IntentInjector::IntentInjector(TabContents* tab_contents) | 18 IntentInjector::IntentInjector(TabContents* tab_contents) |
| 19 : TabContentsObserver(tab_contents), | 19 : TabContentsObserver(tab_contents), |
| 20 source_tab_(NULL) { | 20 intents_dispatcher_(NULL) { |
| 21 DCHECK(tab_contents); | 21 DCHECK(tab_contents); |
| 22 } | 22 } |
| 23 | 23 |
| 24 IntentInjector::~IntentInjector() { | 24 IntentInjector::~IntentInjector() { |
| 25 } | 25 } |
| 26 | 26 |
| 27 void IntentInjector::TabContentsDestroyed(TabContents* tab) { | 27 void IntentInjector::TabContentsDestroyed(TabContents* tab) { |
| 28 if (source_tab_) { | 28 if (intents_dispatcher_) { |
| 29 source_tab_->SendReplyMessage(webkit_glue::WEB_INTENT_SERVICE_TAB_CLOSED, | 29 intents_dispatcher_->SendReplyMessage( |
| 30 string16()); | 30 webkit_glue::WEB_INTENT_SERVICE_TAB_CLOSED, string16()); |
| 31 } | 31 } |
| 32 | 32 |
| 33 delete this; | 33 delete this; |
| 34 } | 34 } |
| 35 | 35 |
| 36 void IntentInjector::SourceTabContentsDestroyed(TabContents* tab) { | 36 void IntentInjector::SourceTabContentsDestroyed(TabContents* tab) { |
| 37 source_tab_ = NULL; | 37 intents_dispatcher_ = NULL; |
| 38 } | 38 } |
| 39 | 39 |
| 40 void IntentInjector::SetIntent(content::IntentsHost* source_tab, | 40 void IntentInjector::SetIntent( |
| 41 const webkit_glue::WebIntentData& intent) { | 41 content::WebIntentsDispatcher* intents_dispatcher, |
| 42 source_tab_ = source_tab; | 42 const webkit_glue::WebIntentData& intent) { |
| 43 intents_dispatcher_ = intents_dispatcher; |
| 43 source_intent_.reset(new webkit_glue::WebIntentData(intent)); | 44 source_intent_.reset(new webkit_glue::WebIntentData(intent)); |
| 44 | 45 |
| 45 SendIntent(); | 46 SendIntent(); |
| 46 } | 47 } |
| 47 | 48 |
| 48 void IntentInjector::RenderViewCreated(RenderViewHost* host) { | 49 void IntentInjector::RenderViewCreated(RenderViewHost* host) { |
| 49 SendIntent(); | 50 SendIntent(); |
| 50 } | 51 } |
| 51 | 52 |
| 52 void IntentInjector::DidNavigateMainFrame( | 53 void IntentInjector::DidNavigateMainFrame( |
| (...skipping 30 matching lines...) Expand all Loading... |
| 83 IPC_MESSAGE_UNHANDLED(handled = false) | 84 IPC_MESSAGE_UNHANDLED(handled = false) |
| 84 IPC_END_MESSAGE_MAP() | 85 IPC_END_MESSAGE_MAP() |
| 85 return handled; | 86 return handled; |
| 86 } | 87 } |
| 87 | 88 |
| 88 void IntentInjector::OnReply(webkit_glue::WebIntentReplyType reply_type, | 89 void IntentInjector::OnReply(webkit_glue::WebIntentReplyType reply_type, |
| 89 const string16& data) { | 90 const string16& data) { |
| 90 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableWebIntents)) | 91 if (!CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnableWebIntents)) |
| 91 NOTREACHED(); | 92 NOTREACHED(); |
| 92 | 93 |
| 93 if (source_tab_) { | 94 if (intents_dispatcher_) { |
| 94 source_tab_->SendReplyMessage(reply_type, data); | 95 intents_dispatcher_->SendReplyMessage(reply_type, data); |
| 95 } | 96 } |
| 96 } | 97 } |
| OLD | NEW |