Commit 13761797 authored by gbillock@chromium.org's avatar gbillock@chromium.org

Mark down in web intents picker controller when it is part of a TabContents...

Mark down in web intents picker controller when it is part of a TabContents that is hosting a web intents service.


R=groby@chromium.org
BUG=None
TEST=WebIntentsPickerControllerBrowserTest.*


Review URL: https://chromiumcodereview.appspot.com/10805094

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@149039 0039d316-1c4b-4281-b951-d872f2087c98
parent 85d9c80b
......@@ -35,6 +35,7 @@
#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/notification_source.h"
#include "content/public/browser/web_contents.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/public/browser/web_intents_dispatcher.h"
#include "grit/generated_resources.h"
#include "ipc/ipc_message.h"
......@@ -137,6 +138,25 @@ void URLFetcherTrampoline::OnURLFetchComplete(
delete this;
}
class SourceWindowObserver : content::WebContentsObserver {
public:
SourceWindowObserver(content::WebContents* web_contents,
base::WeakPtr<WebIntentPickerController> controller)
: content::WebContentsObserver(web_contents),
controller_(controller) {}
virtual ~SourceWindowObserver() {}
// Implement WebContentsObserver
virtual void WebContentsDestroyed(content::WebContents* web_contents) {
if (controller_)
controller_->SourceWebContentsDestroyed(web_contents);
delete this;
}
private:
base::WeakPtr<WebIntentPickerController> controller_;
};
} // namespace
WebIntentPickerController::WebIntentPickerController(
......@@ -147,6 +167,8 @@ WebIntentPickerController::WebIntentPickerController(
pending_async_count_(0),
pending_registry_calls_count_(0),
picker_shown_(false),
window_disposition_source_(NULL),
source_intents_dispatcher_(NULL),
intents_dispatcher_(NULL),
service_tab_(NULL),
weak_ptr_factory_(this) {
......@@ -247,7 +269,7 @@ void WebIntentPickerController::ShowDialog(const string16& action,
action, type,
base::Bind(&WebIntentPickerController::OnCWSIntentServicesAvailable,
weak_ptr_factory_.GetWeakPtr()));
}
}
void WebIntentPickerController::Observe(
int type,
......@@ -291,6 +313,11 @@ void WebIntentPickerController::OnServiceChosen(const GURL& url,
tab_contents_->profile(), url),
MSG_ROUTING_NONE, NULL, NULL);
// Let the controller for the target TabContents know that it is hosting a
// web intents service.
contents->web_intent_picker_controller()->SetWindowDispositionSource(
tab_contents_->web_contents(), intents_dispatcher_);
intents_dispatcher_->DispatchIntent(contents->web_contents());
service_tab_ = contents->web_contents();
......@@ -681,6 +708,38 @@ void WebIntentPickerController::OnExtensionIconUnavailable(
AsyncOperationFinished();
}
void WebIntentPickerController::SetWindowDispositionSource(
content::WebContents* source,
content::WebIntentsDispatcher* dispatcher) {
window_disposition_source_ = source;
if (window_disposition_source_) {
// This object is self-deleting when the source WebContents is destroyed.
new SourceWindowObserver(window_disposition_source_,
weak_ptr_factory_.GetWeakPtr());
}
source_intents_dispatcher_ = dispatcher;
if (dispatcher) {
dispatcher->RegisterReplyNotification(
base::Bind(&WebIntentPickerController::SourceDispatcherReplied,
weak_ptr_factory_.GetWeakPtr()));
}
}
void WebIntentPickerController::SourceWebContentsDestroyed(
content::WebContents* source) {
window_disposition_source_ = NULL;
}
void WebIntentPickerController::SourceDispatcherReplied(
webkit_glue::WebIntentReplyType reply_type) {
source_intents_dispatcher_ = NULL;
}
bool WebIntentPickerController::ShowLocationBarPickerTool() {
return window_disposition_source_ || source_intents_dispatcher_;
}
void WebIntentPickerController::OnExtensionInstallServiceAvailable(
const std::vector<webkit_glue::WebIntentServiceData>& services) {
DCHECK(services.size() > 0);
......
......@@ -57,6 +57,15 @@ class WebIntentPickerController
void ShowDialog(const string16& action,
const string16& type);
// Called by the location bar to see whether the web intents picker affordance
// should be shown. TODO(gbillock): refactor this into a
// LocationBarPageToolModel.
bool ShowLocationBarPickerTool();
// Called to notify a controller for a page hosting a web intents service
// that the source WebContents has been destroyed.
void SourceWebContentsDestroyed(content::WebContents* source);
protected:
// content::NotificationObserver implementation.
virtual void Observe(int type,
......@@ -84,7 +93,6 @@ class WebIntentPickerController
friend class WebIntentPickerControllerTest;
friend class WebIntentPickerControllerBrowserTest;
friend class WebIntentPickerControllerIncognitoBrowserTest;
friend class InvokingTabObserver;
// Gets a notification when the return message is sent to the source tab,
// so we can close the picker dialog or service tab.
......@@ -98,6 +106,15 @@ class WebIntentPickerController
picker_model_->set_observer(observer);
}
// Notify the controller that its TabContents is hosting a web intents
// service. Sets the source and dispatcher for the invoking client.
void SetWindowDispositionSource(content::WebContents* source,
content::WebIntentsDispatcher* dispatcher);
// Called to notify a controller for a page hosting a web intents service
// that the source dispatcher has been replied on.
void SourceDispatcherReplied(webkit_glue::WebIntentReplyType reply_type);
// Called by the WebIntentsRegistry, returning |services|, which is
// a list of WebIntentServiceData matching the query.
void OnWebIntentServicesAvailable(
......@@ -189,6 +206,15 @@ class WebIntentPickerController
// case, a picker may be non-NULL before it is shown.
bool picker_shown_;
// Weak pointer to the source WebContents for the intent if the TabContents
// with which this controller is associated is hosting a web intents window
// disposition service.
content::WebContents* window_disposition_source_;
// If this tab is hosting a web intents service, a weak pointer to dispatcher
// that invoked us. Weak pointer.
content::WebIntentsDispatcher* source_intents_dispatcher_;
// Weak pointer to the routing object for the renderer which launched the
// intent. Contains the intent data and a way to signal back to the
// client page.
......
......@@ -222,6 +222,11 @@ class WebIntentPickerControllerBrowserTest : public InProcessBrowserTest {
host_resolver()->AddRule("www.example.com", "127.0.0.1");
}
content::WebContents* GetWindowDispositionTarget(
WebIntentPickerController* controller) {
return controller->window_disposition_source_;
}
virtual void SetUpOnMainThread() OVERRIDE {
// The FakeURLFetcherFactory will return a NULL URLFetcher if a request is
// created for a URL it doesn't know and there is no default factory.
......@@ -352,6 +357,9 @@ IN_PROC_BROWSER_TEST_F(WebIntentPickerControllerBrowserTest, ChooseService) {
EXPECT_EQ(GURL(kServiceURL2),
chrome::GetActiveWebContents(browser())->GetURL());
EXPECT_TRUE(GetWindowDispositionTarget(
chrome::GetActiveTabContents(browser())->web_intent_picker_controller()));
EXPECT_TRUE(dispatcher.dispatched_);
OnSendReturnMessage(webkit_glue::WEB_INTENT_REPLY_SUCCESS);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment