blob: 30b9c7a616d41a48cf3363a52c13b7eaae4fafac (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CONTENT_BROWSER_INTENTS_INTENT_INJECTOR_H_
#define CONTENT_BROWSER_INTENTS_INTENT_INJECTOR_H_
#pragma once
#include "base/basictypes.h"
#include "base/memory/scoped_ptr.h"
#include "base/string16.h"
#include "content/public/browser/web_contents_observer.h"
#include "content/common/content_export.h"
#include "googleurl/src/gurl.h"
#include "webkit/glue/web_intent_reply_data.h"
namespace content {
class WebIntentsDispatcher;
}
namespace webkit_glue {
struct WebIntentData;
}
// Injects an intent into the renderer of a WebContents. The intent dispatch
// logic will create one of these to take care of passing intent data down into
// the context of the service, which will be running in the WebContents on which
// this class is an observer. Attaches to the service contents and deletes
// itself when that WebContents is closed.
//
// This object should be attached to the new WebContents very early: before the
// RenderView is created. It will then send the intent data down to the renderer
// on the RenderViewCreated call, so that the intent data is available
// throughout the parsing of the loaded document.
class CONTENT_EXPORT IntentInjector : public content::WebContentsObserver {
public:
// |web_contents| must not be NULL.
explicit IntentInjector(content::WebContents* web_contents);
virtual ~IntentInjector();
// content::WebContentsObserver implementation.
virtual void RenderViewCreated(
content::RenderViewHost* render_view_host) OVERRIDE;
virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
virtual void WebContentsDestroyed(content::WebContents* contents) OVERRIDE;
// Used to notify the object that the source contents has been destroyed.
void SourceWebContentsDestroyed(content::WebContents* contents);
// Sets the intent data to be injected. Call after the user has selected a
// service to pass the intent data to that service. |intents_dispatcher| is a
// sender to use to communicate to the source contents. The caller must
// ensure that SourceWebContentsDestroyed is called when this object becomes
// unusable. |intent| is the intent data from the source.
void SetIntent(content::WebIntentsDispatcher* intents_dispatcher,
const webkit_glue::WebIntentData& intent);
private:
// Handles receiving a reply from the intent delivery page.
void OnReply(webkit_glue::WebIntentReplyType reply_type,
const string16& data);
// Gets notification that someone else has replied to the intent call.
void OnSendReturnMessage(webkit_glue::WebIntentReplyType reply_type);
// Source intent data provided by caller.
scoped_ptr<webkit_glue::WebIntentData> source_intent_;
// Weak pointer to the message forwarder to the contents invoking the intent.
content::WebIntentsDispatcher* intents_dispatcher_;
// Remember the initial delivery url for origin restriction.
GURL initial_url_;
DISALLOW_COPY_AND_ASSIGN(IntentInjector);
};
#endif // CONTENT_BROWSER_INTENTS_INTENT_INJECTOR_H_
|