[content shell] implement testRunner.overridePreference
[chromium-blink-merge.git] / content / renderer / web_intents_host.h
blobefc37b3549bc16891e3047b4eff7445ee9e30915
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
3 // found in the LICENSE file.
5 #ifndef CONTENT_RENDERER_WEB_INTENTS_HOST_H_
6 #define CONTENT_RENDERER_WEB_INTENTS_HOST_H_
8 #include <map>
10 #include "base/memory/scoped_ptr.h"
11 #include "content/public/renderer/render_view_observer.h"
12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebBlob.h"
13 #include "third_party/WebKit/Source/WebKit/chromium/public/WebIntent.h"
14 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
15 #include "v8/include/v8.h"
16 #include "webkit/glue/web_intent_data.h"
17 #include "webkit/glue/web_intent_reply_data.h"
19 namespace WebKit {
20 class WebDeliveredIntentClient;
21 class WebIntentRequest;
22 class WebFrame;
25 namespace webkit_glue {
26 struct WebIntentData;
29 namespace content {
30 class RenderViewImpl;
32 // WebIntentsHost is a delegate for Web Intents messages. It is the
33 // renderer-side handler for IPC messages delivering the intent payload data
34 // and preparing it for access by the service page.
35 class WebIntentsHost : public RenderViewObserver {
36 public:
37 // |render_view| must not be NULL.
38 explicit WebIntentsHost(RenderViewImpl* render_view);
39 virtual ~WebIntentsHost();
41 // Called by the RenderView to register a new Web Intent invocation.
42 int RegisterWebIntent(const WebKit::WebIntentRequest& request);
44 // Called into when the delivered intent object gets a postResult call.
45 void OnResult(const WebKit::WebString& data);
46 // Called into when the delivered intent object gets a postFailure call.
47 void OnFailure(const WebKit::WebString& data);
49 // Forwarded from RenderViewImpl. Notification that a new script context was
50 // created within webkit.
51 virtual void DidCreateScriptContext(WebKit::WebFrame* frame,
52 v8::Handle<v8::Context> ctx,
53 int extension_group,
54 int world_id);
56 private:
57 // RenderView::Observer implementation.
58 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
60 // Converts incoming intent data to a WebIntent object.
61 WebKit::WebIntent CreateWebIntent(
62 WebKit::WebFrame* frame, const webkit_glue::WebIntentData& intent_data);
64 // TODO(gbillock): Do we need various ***ClientRedirect methods to implement
65 // intent cancelling policy? Figure this out.
67 // On the service page, handler method for the IntentsMsg_SetWebIntent
68 // message.
69 CONTENT_EXPORT void OnSetIntent(const webkit_glue::WebIntentData& intent);
71 // On the client page, handler method for the IntentsMsg_WebIntentReply
72 // message. Forwards |reply| to the registered WebIntentRequest
73 // (found by |intent_id|), where it is dispatched to the client JS callback.
74 void OnWebIntentReply(const webkit_glue::WebIntentReply& reply,
75 int intent_id);
77 friend class WebIntentsHostTest;
79 // A counter used to assign unique IDs to web intents invocations in this
80 // renderer.
81 int id_counter_;
83 // Map tracking registered Web Intent requests by assigned ID numbers to
84 // correctly route any return data.
85 std::map<int, WebKit::WebIntentRequest> intent_requests_;
87 // Delivered intent data from the caller.
88 scoped_ptr<webkit_glue::WebIntentData> intent_;
90 // The client object which will receive callback notifications from the
91 // delivered intent.
92 scoped_ptr<WebKit::WebDeliveredIntentClient> delivered_intent_client_;
94 // If we deliver a browser-originated blob intent to the client,
95 // this is that Blob.
96 WebKit::WebBlob web_blob_;
98 DISALLOW_COPY_AND_ASSIGN(WebIntentsHost);
101 } // namespace content
103 #endif // CONTENT_RENDERER_WEB_INTENTS_HOST_H_