1 // Copyright 2014 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 EXTENSIONS_BROWSER_GUEST_VIEW_MIME_HANDLER_VIEW_MIME_HANDLER_VIEW_GUEST_H_
6 #define EXTENSIONS_BROWSER_GUEST_VIEW_MIME_HANDLER_VIEW_MIME_HANDLER_VIEW_GUEST_H_
8 #include "base/memory/weak_ptr.h"
9 #include "components/guest_view/browser/guest_view.h"
10 #include "extensions/browser/extension_function_dispatcher.h"
14 struct ContextMenuParams
;
16 } // namespace content
18 namespace extensions
{
19 class MimeHandlerViewGuestDelegate
;
21 // A container for a StreamHandle and any other information necessary for a
22 // MimeHandler to handle a resource stream.
23 class StreamContainer
{
25 StreamContainer(scoped_ptr
<content::StreamInfo
> stream
,
28 const GURL
& handler_url
,
29 const std::string
& extension_id
);
33 void Abort(const base::Closure
& callback
);
35 base::WeakPtr
<StreamContainer
> GetWeakPtr();
37 const content::StreamInfo
* stream_info() const { return stream_
.get(); }
38 bool embedded() const { return embedded_
; }
39 int tab_id() const { return tab_id_
; }
40 GURL
handler_url() const { return handler_url_
; }
41 std::string
extension_id() const { return extension_id_
; }
44 const scoped_ptr
<content::StreamInfo
> stream_
;
47 const GURL handler_url_
;
48 const std::string extension_id_
;
50 base::WeakPtrFactory
<StreamContainer
> weak_factory_
;
53 class MimeHandlerViewGuest
: public guest_view::GuestView
<MimeHandlerViewGuest
>,
54 public ExtensionFunctionDispatcher::Delegate
{
56 static guest_view::GuestViewBase
* Create(
57 content::WebContents
* owner_web_contents
);
59 static const char Type
[];
61 // ExtensionFunctionDispatcher::Delegate implementation.
62 WindowController
* GetExtensionWindowController() const override
;
63 content::WebContents
* GetAssociatedWebContents() const override
;
65 // GuestViewBase implementation.
66 const char* GetAPINamespace() const override
;
67 int GetTaskPrefix() const override
;
68 void CreateWebContents(const base::DictionaryValue
& create_params
,
69 const WebContentsCreatedCallback
& callback
) override
;
70 void DidAttachToEmbedder() override
;
71 void DidInitialize(const base::DictionaryValue
& create_params
) override
;
72 bool ZoomPropagatesFromEmbedderToGuest() const override
;
74 // content::BrowserPluginGuestDelegate implementation
75 bool Find(int request_id
,
76 const base::string16
& search_text
,
77 const blink::WebFindOptions
& options
) override
;
78 bool StopFinding(content::StopFindAction action
) override
;
80 // WebContentsDelegate implementation.
81 content::WebContents
* OpenURLFromTab(
82 content::WebContents
* source
,
83 const content::OpenURLParams
& params
) override
;
84 bool HandleContextMenu(const content::ContextMenuParams
& params
) override
;
85 bool PreHandleGestureEvent(content::WebContents
* source
,
86 const blink::WebGestureEvent
& event
) override
;
87 content::JavaScriptDialogManager
* GetJavaScriptDialogManager(
88 content::WebContents
* source
) override
;
89 void FindReply(content::WebContents
* web_contents
,
91 int number_of_matches
,
92 const gfx::Rect
& selection_rect
,
93 int active_match_ordinal
,
94 bool final_update
) override
;
95 bool SaveFrame(const GURL
& url
, const content::Referrer
& referrer
) override
;
97 // content::WebContentsObserver implementation.
98 void DocumentOnLoadCompletedInMainFrame() override
;
99 bool OnMessageReceived(const IPC::Message
& message
) override
;
101 std::string
view_id() const { return view_id_
; }
102 base::WeakPtr
<StreamContainer
> GetStream() const;
105 explicit MimeHandlerViewGuest(content::WebContents
* owner_web_contents
);
106 ~MimeHandlerViewGuest() override
;
109 void OnRequest(const ExtensionHostMsg_Request_Params
& params
);
111 scoped_ptr
<MimeHandlerViewGuestDelegate
> delegate_
;
112 scoped_ptr
<ExtensionFunctionDispatcher
> extension_function_dispatcher_
;
113 scoped_ptr
<StreamContainer
> stream_
;
114 std::string view_id_
;
116 DISALLOW_COPY_AND_ASSIGN(MimeHandlerViewGuest
);
119 } // namespace extensions
121 #endif // EXTENSIONS_BROWSER_GUEST_VIEW_MIME_HANDLER_VIEW_MIME_HANDLER_VIEW_GUEST_H_