#include "common/web_contents_utils.h"
#include "common/render_messages_ewk.h"
+#include "content/common/view_messages.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
using content::WebContents;
using namespace web_contents_utils;
-namespace tizen_webview {
-
class WebViewBrowserMessageFilterPrivate
: public content::NotificationObserver {
public:
}
}
+ void OnPlainTextGetContents(const std::string& content_text, int plain_text_get_callback_id) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ if (web_view_)
+ web_view_->InvokePlainTextGetCallback(content_text, plain_text_get_callback_id);
+ }
+
+ void OnWebAppIconUrlGet(const std::string &icon_url, int callback_id) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ if (web_view_)
+ web_view_->InvokeWebAppIconUrlGetCallback(icon_url, callback_id);
+ }
+
+ void OnWebAppIconUrlsGet(const std::map<std::string, std::string> &icon_urls, int callback_id) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ if (web_view_)
+ web_view_->InvokeWebAppIconUrlsGetCallback(icon_urls, callback_id);
+ }
+
+ void OnWebAppCapableGet(bool capable, int callback_id) {
+ DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
+ if (web_view_)
+ web_view_->InvokeWebAppCapableGetCallback(capable, callback_id);
+ }
+
+ void OnDidChangeContentsSize(int width, int height) {
+ DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
+ if (web_view_)
+ web_view_->DidChangeContentsSize(width, height);
+ }
+
+ void OnSelectionTextStyleState(const SelectionStylePrams& params) {
+ if (web_view_)
+ web_view_->OnQuerySelectionStyleReply(params);
+ }
+
+ void OnDidChangePageScaleFactor(double scale_factor) {
+ if (web_view_)
+ web_view_->DidChangePageScaleFactor(scale_factor);
+ }
+
+ void OnMHTMLContentGet(const std::string& mhtml_content, int callback_id) {
+ if (web_view_)
+ web_view_->OnMHTMLContentGet(mhtml_content, callback_id);
+ }
+
+ void OnDidChangePageScaleRange(double min_scale, double max_scale) {
+ if (web_view_)
+ web_view_->DidChangePageScaleRange(min_scale, max_scale);
+ }
+
+ void OnSnapshot(const std::vector<unsigned char> pixData, int snapshotId, const gfx::Size& size) {
+ if (web_view_)
+ web_view_->OnSnapshot(pixData, size.width(), size.height(), snapshotId);
+ }
+
+ void OnGetTextAtPositionReply(const std::string& text) {
+#ifdef TIZEN_CONTENTS_DETECTION
+ if (web_view_) {
+ base::string16 content = base::UTF8ToUTF16(text);
+
+ std::string message;
+ if (autofill::IsValidEmailAddress(content))
+ message = std::string("mailto:").append(text);
+ else if (autofill::IsValidPhoneNumber(content))
+ message = std::string("tel:").append(text);
+ else
+ return;
+
+ web_view_->ShowContentsDetectedPopup(message.c_str());
+ }
+#endif
+ }
+
void Observe(int type, const content::NotificationSource& source,
const content::NotificationDetails& details) override {
DCHECK_EQ(content::NOTIFICATION_WEB_CONTENTS_DESTROYED, type);
WebViewBrowserMessageFilterPrivate::OnReceivedHitTestAsyncData)
IPC_MESSAGE_FORWARD(EwkViewMsg_DidFailLoadWithError, private_,
WebViewBrowserMessageFilterPrivate::OnReceivedDidFailLoadWithError)
+ IPC_MESSAGE_FORWARD(EwkHostMsg_PlainTextGetContents, private_,
+ WebViewBrowserMessageFilterPrivate::OnPlainTextGetContents)
+ IPC_MESSAGE_FORWARD(EwkHostMsg_WebAppIconUrlGet, private_,
+ WebViewBrowserMessageFilterPrivate::OnWebAppIconUrlGet)
+ IPC_MESSAGE_FORWARD(EwkHostMsg_WebAppIconUrlsGet, private_,
+ WebViewBrowserMessageFilterPrivate::OnWebAppIconUrlsGet)
+ IPC_MESSAGE_FORWARD(EwkHostMsg_WebAppCapableGet, private_,
+ WebViewBrowserMessageFilterPrivate::OnWebAppCapableGet)
+ IPC_MESSAGE_FORWARD(EwkHostMsg_DidChangeContentsSize, private_,
+ WebViewBrowserMessageFilterPrivate::OnDidChangeContentsSize)
+ IPC_MESSAGE_FORWARD(EwkViewMsg_SelectionTextStyleState, private_,
+ WebViewBrowserMessageFilterPrivate::OnSelectionTextStyleState)
+ IPC_MESSAGE_FORWARD(EwkHostMsg_ReadMHTMLData, private_,
+ WebViewBrowserMessageFilterPrivate::OnMHTMLContentGet)
+ IPC_MESSAGE_FORWARD(EwkHostMsg_DidChangePageScaleFactor, private_,
+ WebViewBrowserMessageFilterPrivate::OnDidChangePageScaleFactor)
+ IPC_MESSAGE_FORWARD(EwkHostMsg_DidChangePageScaleRange, private_,
+ WebViewBrowserMessageFilterPrivate::OnDidChangePageScaleRange)
+#if defined(OS_TIZEN)
+ IPC_MESSAGE_FORWARD(ViewHostMsg_SnapshotDataReceived, private_,
+ WebViewBrowserMessageFilterPrivate::OnSnapshot)
+ IPC_MESSAGE_FORWARD(ViewHostMsg_GetTextAtPositionReply, private_,
+ WebViewBrowserMessageFilterPrivate::OnGetTextAtPositionReply)
+#endif
+
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}
-
-} // namespace tizen_webview
Callback callback_;
};
-class WebViewBrowserMessageFilter: public content::BrowserMessageFilter
-{
- public:
- WebViewBrowserMessageFilter(EWebView* web_view)
- : BrowserMessageFilter(EwkMsgStart)
- , web_view_(web_view) {
- WebContents* web_contents = GetWebContents();
- DCHECK(web_contents);
-
- if (web_contents && web_contents->GetRenderProcessHost())
- web_contents->GetRenderProcessHost()->AddFilter(this);
- }
-
- virtual void OverrideThreadForMessage(const IPC::Message& message,
- BrowserThread::ID* thread) override {
- if (message.type() == EwkViewHostMsg_HitTestAsyncReply::ID)
- *thread = BrowserThread::UI;
- }
-
- virtual bool OnMessageReceived(const IPC::Message& message) override {
- bool handled = true;
- IPC_BEGIN_MESSAGE_MAP(WebViewBrowserMessageFilter, message)
- IPC_MESSAGE_HANDLER(EwkViewHostMsg_HitTestReply, OnReceivedHitTestData)
- IPC_MESSAGE_HANDLER(EwkViewHostMsg_HitTestAsyncReply, OnReceivedHitTestAsyncData)
- IPC_MESSAGE_UNHANDLED(handled = false)
- IPC_END_MESSAGE_MAP()
- return handled;
- }
-
- private:
- void OnReceivedHitTestData(int render_view, const _Ewk_Hit_Test& hit_test_data,
- const NodeAttributesMap& node_attributes) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
-
- RenderViewHost* render_view_host= web_view_->web_contents().GetRenderViewHost();
- CHECK(render_view_host);
-
- if (render_view_host && render_view_host->GetRoutingID() == render_view)
- web_view_->UpdateHitTestData(hit_test_data, node_attributes);
- }
-
- void OnReceivedHitTestAsyncData(int render_view, const _Ewk_Hit_Test& hit_test_data,
- const NodeAttributesMap& node_attributes, int64_t request_id) {
- DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI));
- WebContents* contents = GetWebContents();
- CHECK(contents);
-
- RenderViewHost* render_view_host= contents->GetRenderViewHost();
- CHECK(render_view_host);
- if (render_view_host && render_view_host->GetRoutingID() == render_view)
- web_view_->DispatchAsyncHitTestData(hit_test_data, node_attributes, request_id);
- }
-
- WebContents* GetWebContents() const {
- if (web_view_)
- return &(web_view_->web_contents());
-
- return NULL;
- }
-
- private:
- EWebView* web_view_;
-};
-
class AsyncHitTestRequest
{
public:
web_contents_->GetRenderViewHost()->SyncRendererPrefs();
}
-void EWebView::FindAndRunSnapshotCallback(Evas_Object* image, int snapshotId) {
+void EWebView::OnSnapshot(const std::vector<unsigned char>& pixData, int width, int height, int snapshotId) {
WebAppScreenshotCapturedCallback* callback = screen_capture_cb_map_.Lookup(snapshotId);
if (!callback) {
return;
}
+
+ Evas_Object* image = evas_object_image_filled_add(rwhv()->evas());
+ evas_object_image_size_set(image, width, height);
+ evas_object_image_data_copy_set(image, const_cast<unsigned char*>(&pixData[0]));
+
callback->Run(image);
screen_capture_cb_map_.Remove(snapshotId);
}