Merge pull request #3288 from deepak1556/flash_context_menu_pathc
browser: handle flash context menu request
This commit is contained in:
commit
56e6b28370
10 changed files with 177 additions and 22 deletions
|
@ -19,7 +19,7 @@
|
||||||
#include "atom/browser/browser.h"
|
#include "atom/browser/browser.h"
|
||||||
#include "atom/browser/login_handler.h"
|
#include "atom/browser/login_handler.h"
|
||||||
#include "atom/common/native_mate_converters/callback.h"
|
#include "atom/common/native_mate_converters/callback.h"
|
||||||
#include "atom/common/native_mate_converters/content_converter.h"
|
#include "atom/common/native_mate_converters/net_converter.h"
|
||||||
#include "atom/common/native_mate_converters/file_path_converter.h"
|
#include "atom/common/native_mate_converters/file_path_converter.h"
|
||||||
#include "atom/common/node_includes.h"
|
#include "atom/common/node_includes.h"
|
||||||
#include "atom/common/options_switches.h"
|
#include "atom/common/options_switches.h"
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
#include "atom/browser/net/url_request_fetch_job.h"
|
#include "atom/browser/net/url_request_fetch_job.h"
|
||||||
#include "atom/browser/net/url_request_string_job.h"
|
#include "atom/browser/net/url_request_string_job.h"
|
||||||
#include "atom/common/native_mate_converters/callback.h"
|
#include "atom/common/native_mate_converters/callback.h"
|
||||||
#include "atom/common/native_mate_converters/content_converter.h"
|
#include "atom/common/native_mate_converters/net_converter.h"
|
||||||
#include "atom/common/node_includes.h"
|
#include "atom/common/node_includes.h"
|
||||||
#include "native_mate/dictionary.h"
|
#include "native_mate/dictionary.h"
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include "atom/common/api/event_emitter_caller.h"
|
#include "atom/common/api/event_emitter_caller.h"
|
||||||
#include "atom/common/native_mate_converters/blink_converter.h"
|
#include "atom/common/native_mate_converters/blink_converter.h"
|
||||||
#include "atom/common/native_mate_converters/callback.h"
|
#include "atom/common/native_mate_converters/callback.h"
|
||||||
|
#include "atom/common/native_mate_converters/content_converter.h"
|
||||||
#include "atom/common/native_mate_converters/file_path_converter.h"
|
#include "atom/common/native_mate_converters/file_path_converter.h"
|
||||||
#include "atom/common/native_mate_converters/gfx_converter.h"
|
#include "atom/common/native_mate_converters/gfx_converter.h"
|
||||||
#include "atom/common/native_mate_converters/gurl_converter.h"
|
#include "atom/common/native_mate_converters/gurl_converter.h"
|
||||||
|
@ -405,6 +406,12 @@ void WebContents::RendererResponsive(content::WebContents* source) {
|
||||||
owner_window()->RendererResponsive(source);
|
owner_window()->RendererResponsive(source);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool WebContents::HandleContextMenu(const content::ContextMenuParams& params) {
|
||||||
|
context_menu_context_ = params.custom_context;
|
||||||
|
Emit("-context-menu", params);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void WebContents::BeforeUnloadFired(const base::TimeTicks& proceed_time) {
|
void WebContents::BeforeUnloadFired(const base::TimeTicks& proceed_time) {
|
||||||
// Do nothing, we override this method just to avoid compilation error since
|
// Do nothing, we override this method just to avoid compilation error since
|
||||||
// there are two virtual functions named BeforeUnloadFired.
|
// there are two virtual functions named BeforeUnloadFired.
|
||||||
|
@ -841,6 +848,15 @@ void WebContents::RemoveWorkSpace(mate::Arguments* args,
|
||||||
DevToolsRemoveFileSystem(path);
|
DevToolsRemoveFileSystem(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebContents::ExecuteContextMenuCommand(int action) {
|
||||||
|
web_contents()->ExecuteCustomContextMenuCommand(action,
|
||||||
|
context_menu_context_);
|
||||||
|
}
|
||||||
|
|
||||||
|
void WebContents::NotifyContextMenuClosed() {
|
||||||
|
web_contents()->NotifyContextMenuClosed(context_menu_context_);
|
||||||
|
}
|
||||||
|
|
||||||
void WebContents::Undo() {
|
void WebContents::Undo() {
|
||||||
web_contents()->Undo();
|
web_contents()->Undo();
|
||||||
}
|
}
|
||||||
|
@ -1052,6 +1068,10 @@ mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder(
|
||||||
.SetMethod("_printToPDF", &WebContents::PrintToPDF)
|
.SetMethod("_printToPDF", &WebContents::PrintToPDF)
|
||||||
.SetMethod("addWorkSpace", &WebContents::AddWorkSpace)
|
.SetMethod("addWorkSpace", &WebContents::AddWorkSpace)
|
||||||
.SetMethod("removeWorkSpace", &WebContents::RemoveWorkSpace)
|
.SetMethod("removeWorkSpace", &WebContents::RemoveWorkSpace)
|
||||||
|
.SetMethod("_executeContextMenuCommand",
|
||||||
|
&WebContents::ExecuteContextMenuCommand)
|
||||||
|
.SetMethod("_notifyContextMenuClosed",
|
||||||
|
&WebContents::NotifyContextMenuClosed)
|
||||||
.SetProperty("session", &WebContents::Session, true)
|
.SetProperty("session", &WebContents::Session, true)
|
||||||
.SetProperty("devToolsWebContents",
|
.SetProperty("devToolsWebContents",
|
||||||
&WebContents::DevToolsWebContents, true)
|
&WebContents::DevToolsWebContents, true)
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include "atom/browser/api/trackable_object.h"
|
#include "atom/browser/api/trackable_object.h"
|
||||||
#include "atom/browser/common_web_contents_delegate.h"
|
#include "atom/browser/common_web_contents_delegate.h"
|
||||||
#include "content/public/browser/web_contents_observer.h"
|
#include "content/public/browser/web_contents_observer.h"
|
||||||
|
#include "content/public/common/context_menu_params.h"
|
||||||
#include "content/public/common/favicon_url.h"
|
#include "content/public/common/favicon_url.h"
|
||||||
#include "native_mate/handle.h"
|
#include "native_mate/handle.h"
|
||||||
#include "ui/gfx/image/image.h"
|
#include "ui/gfx/image/image.h"
|
||||||
|
@ -92,6 +93,8 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||||
void SetAudioMuted(bool muted);
|
void SetAudioMuted(bool muted);
|
||||||
bool IsAudioMuted();
|
bool IsAudioMuted();
|
||||||
void Print(mate::Arguments* args);
|
void Print(mate::Arguments* args);
|
||||||
|
void ExecuteContextMenuCommand(int action);
|
||||||
|
void NotifyContextMenuClosed();
|
||||||
|
|
||||||
// Print current page as PDF.
|
// Print current page as PDF.
|
||||||
void PrintToPDF(const base::DictionaryValue& setting,
|
void PrintToPDF(const base::DictionaryValue& setting,
|
||||||
|
@ -189,6 +192,7 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||||
void ExitFullscreenModeForTab(content::WebContents* source) override;
|
void ExitFullscreenModeForTab(content::WebContents* source) override;
|
||||||
void RendererUnresponsive(content::WebContents* source) override;
|
void RendererUnresponsive(content::WebContents* source) override;
|
||||||
void RendererResponsive(content::WebContents* source) override;
|
void RendererResponsive(content::WebContents* source) override;
|
||||||
|
bool HandleContextMenu(const content::ContextMenuParams& params) override;
|
||||||
|
|
||||||
// content::WebContentsObserver:
|
// content::WebContentsObserver:
|
||||||
void BeforeUnloadFired(const base::TimeTicks& proceed_time) override;
|
void BeforeUnloadFired(const base::TimeTicks& proceed_time) override;
|
||||||
|
@ -255,6 +259,9 @@ class WebContents : public mate::TrackableObject<WebContents>,
|
||||||
// embedders' zoom level change.
|
// embedders' zoom level change.
|
||||||
void OnZoomLevelChanged(double level);
|
void OnZoomLevelChanged(double level);
|
||||||
|
|
||||||
|
// Recent unhandled context menu context.
|
||||||
|
content::CustomContextMenuContext context_menu_context_;
|
||||||
|
|
||||||
v8::Global<v8::Value> session_;
|
v8::Global<v8::Value> session_;
|
||||||
v8::Global<v8::Value> devtools_web_contents_;
|
v8::Global<v8::Value> devtools_web_contents_;
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
EventEmitter = require('events').EventEmitter
|
EventEmitter = require('events').EventEmitter
|
||||||
|
Menu = require './menu'
|
||||||
NavigationController = require './navigation-controller'
|
NavigationController = require './navigation-controller'
|
||||||
binding = process.atomBinding 'web_contents'
|
binding = process.atomBinding 'web_contents'
|
||||||
ipc = require 'ipc'
|
ipc = require 'ipc'
|
||||||
|
@ -34,6 +35,36 @@ PDFPageSize =
|
||||||
width_microns: 279400
|
width_microns: 279400
|
||||||
custom_display_name: "Tabloid"
|
custom_display_name: "Tabloid"
|
||||||
|
|
||||||
|
clickHandler = (action) ->
|
||||||
|
@_executeContextMenuCommand action
|
||||||
|
|
||||||
|
convertToMenuTemplate = (items, handler) ->
|
||||||
|
template = []
|
||||||
|
for item in items
|
||||||
|
do (item) ->
|
||||||
|
transformed =
|
||||||
|
if item.type is 'submenu'
|
||||||
|
type: 'submenu'
|
||||||
|
label: item.label
|
||||||
|
enabled: item.enabled
|
||||||
|
submenu: convertToMenuTemplate item.subItems, handler
|
||||||
|
else if item.type is 'separator'
|
||||||
|
type: 'separator'
|
||||||
|
else if item.type is 'checkbox'
|
||||||
|
type: 'checkbox'
|
||||||
|
label: item.label
|
||||||
|
enabled: item.enabled
|
||||||
|
checked: item.checked
|
||||||
|
else
|
||||||
|
type: 'normal'
|
||||||
|
label: item.label
|
||||||
|
enabled: item.enabled
|
||||||
|
if item.id?
|
||||||
|
transformed.click = ->
|
||||||
|
handler item.id
|
||||||
|
template.push transformed
|
||||||
|
template
|
||||||
|
|
||||||
wrapWebContents = (webContents) ->
|
wrapWebContents = (webContents) ->
|
||||||
# webContents is an EventEmitter.
|
# webContents is an EventEmitter.
|
||||||
webContents.__proto__ = EventEmitter.prototype
|
webContents.__proto__ = EventEmitter.prototype
|
||||||
|
@ -65,6 +96,16 @@ wrapWebContents = (webContents) ->
|
||||||
Object.defineProperty event, 'returnValue', set: (value) -> event.sendReply JSON.stringify(value)
|
Object.defineProperty event, 'returnValue', set: (value) -> event.sendReply JSON.stringify(value)
|
||||||
ipc.emit channel, event, args...
|
ipc.emit channel, event, args...
|
||||||
|
|
||||||
|
# Handle context menu action request from renderer widget.
|
||||||
|
webContents.on '-context-menu', (event, params) ->
|
||||||
|
if params.isPepperMenu
|
||||||
|
template = convertToMenuTemplate(params.menuItems, clickHandler.bind(webContents))
|
||||||
|
menu = Menu.buildFromTemplate template
|
||||||
|
# The menu is expected to show asynchronously.
|
||||||
|
setImmediate ->
|
||||||
|
menu.popup params.x, params.y
|
||||||
|
webContents._notifyContextMenuClosed()
|
||||||
|
|
||||||
webContents.printToPDF = (options, callback) ->
|
webContents.printToPDF = (options, callback) ->
|
||||||
printingSetting =
|
printingSetting =
|
||||||
pageRage: []
|
pageRage: []
|
||||||
|
|
|
@ -4,30 +4,50 @@
|
||||||
|
|
||||||
#include "atom/common/native_mate_converters/content_converter.h"
|
#include "atom/common/native_mate_converters/content_converter.h"
|
||||||
|
|
||||||
|
#include "atom/common/native_mate_converters/string16_converter.h"
|
||||||
|
#include "content/public/common/context_menu_params.h"
|
||||||
|
#include "content/public/common/menu_item.h"
|
||||||
#include "native_mate/dictionary.h"
|
#include "native_mate/dictionary.h"
|
||||||
#include "net/url_request/url_request.h"
|
|
||||||
|
|
||||||
namespace mate {
|
namespace mate {
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct Converter<content::MenuItem::Type> {
|
||||||
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||||
|
const content::MenuItem::Type& val) {
|
||||||
|
switch (val) {
|
||||||
|
case content::MenuItem::CHECKABLE_OPTION:
|
||||||
|
return StringToV8(isolate, "checkbox");
|
||||||
|
case content::MenuItem::SEPARATOR:
|
||||||
|
return StringToV8(isolate, "separator");
|
||||||
|
case content::MenuItem::SUBMENU:
|
||||||
|
return StringToV8(isolate, "submenu");
|
||||||
|
default:
|
||||||
|
return StringToV8(isolate, "normal");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
// static
|
// static
|
||||||
v8::Local<v8::Value> Converter<const net::URLRequest*>::ToV8(
|
v8::Local<v8::Value> Converter<content::MenuItem>::ToV8(
|
||||||
v8::Isolate* isolate, const net::URLRequest* val) {
|
v8::Isolate* isolate, const content::MenuItem& val) {
|
||||||
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
|
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
|
||||||
dict.Set("method", val->method());
|
dict.Set("id", val.action);
|
||||||
dict.Set("url", val->url().spec());
|
dict.Set("type", val.type);
|
||||||
dict.Set("referrer", val->referrer());
|
dict.Set("label", val.label);
|
||||||
|
dict.Set("enabled", val.enabled);
|
||||||
|
dict.Set("checked", val.checked);
|
||||||
return mate::ConvertToV8(isolate, dict);
|
return mate::ConvertToV8(isolate, dict);
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
v8::Local<v8::Value> Converter<const net::AuthChallengeInfo*>::ToV8(
|
v8::Local<v8::Value> Converter<content::ContextMenuParams>::ToV8(
|
||||||
v8::Isolate* isolate, const net::AuthChallengeInfo* val) {
|
v8::Isolate* isolate, const content::ContextMenuParams& val) {
|
||||||
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
|
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
|
||||||
dict.Set("isProxy", val->is_proxy);
|
dict.Set("x", val.x);
|
||||||
dict.Set("scheme", val->scheme);
|
dict.Set("y", val.y);
|
||||||
dict.Set("host", val->challenger.host());
|
dict.Set("isPepperMenu", val.custom_context.is_pepper_menu);
|
||||||
dict.Set("port", static_cast<uint32_t>(val->challenger.port()));
|
dict.Set("menuItems", val.custom_items);
|
||||||
dict.Set("realm", val->realm);
|
|
||||||
return mate::ConvertToV8(isolate, dict);
|
return mate::ConvertToV8(isolate, dict);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,23 +7,23 @@
|
||||||
|
|
||||||
#include "native_mate/converter.h"
|
#include "native_mate/converter.h"
|
||||||
|
|
||||||
namespace net {
|
namespace content {
|
||||||
class AuthChallengeInfo;
|
struct ContextMenuParams;
|
||||||
class URLRequest;
|
struct MenuItem;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace mate {
|
namespace mate {
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Converter<const net::URLRequest*> {
|
struct Converter<content::MenuItem> {
|
||||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||||
const net::URLRequest* val);
|
const content::MenuItem& val);
|
||||||
};
|
};
|
||||||
|
|
||||||
template<>
|
template<>
|
||||||
struct Converter<const net::AuthChallengeInfo*> {
|
struct Converter<content::ContextMenuParams> {
|
||||||
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||||
const net::AuthChallengeInfo* val);
|
const content::ContextMenuParams& val);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace mate
|
} // namespace mate
|
||||||
|
|
34
atom/common/native_mate_converters/net_converter.cc
Normal file
34
atom/common/native_mate_converters/net_converter.cc
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
// Copyright (c) 2015 GitHub, Inc.
|
||||||
|
// Use of this source code is governed by the MIT license that can be
|
||||||
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
#include "atom/common/native_mate_converters/net_converter.h"
|
||||||
|
|
||||||
|
#include "native_mate/dictionary.h"
|
||||||
|
#include "net/url_request/url_request.h"
|
||||||
|
|
||||||
|
namespace mate {
|
||||||
|
|
||||||
|
// static
|
||||||
|
v8::Local<v8::Value> Converter<const net::URLRequest*>::ToV8(
|
||||||
|
v8::Isolate* isolate, const net::URLRequest* val) {
|
||||||
|
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
|
||||||
|
dict.Set("method", val->method());
|
||||||
|
dict.Set("url", val->url().spec());
|
||||||
|
dict.Set("referrer", val->referrer());
|
||||||
|
return mate::ConvertToV8(isolate, dict);
|
||||||
|
}
|
||||||
|
|
||||||
|
// static
|
||||||
|
v8::Local<v8::Value> Converter<const net::AuthChallengeInfo*>::ToV8(
|
||||||
|
v8::Isolate* isolate, const net::AuthChallengeInfo* val) {
|
||||||
|
mate::Dictionary dict = mate::Dictionary::CreateEmpty(isolate);
|
||||||
|
dict.Set("isProxy", val->is_proxy);
|
||||||
|
dict.Set("scheme", val->scheme);
|
||||||
|
dict.Set("host", val->challenger.host());
|
||||||
|
dict.Set("port", static_cast<uint32_t>(val->challenger.port()));
|
||||||
|
dict.Set("realm", val->realm);
|
||||||
|
return mate::ConvertToV8(isolate, dict);
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace mate
|
31
atom/common/native_mate_converters/net_converter.h
Normal file
31
atom/common/native_mate_converters/net_converter.h
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
// Copyright (c) 2015 GitHub, Inc.
|
||||||
|
// Use of this source code is governed by the MIT license that can be
|
||||||
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
#ifndef ATOM_COMMON_NATIVE_MATE_CONVERTERS_NET_CONVERTER_H_
|
||||||
|
#define ATOM_COMMON_NATIVE_MATE_CONVERTERS_NET_CONVERTER_H_
|
||||||
|
|
||||||
|
#include "native_mate/converter.h"
|
||||||
|
|
||||||
|
namespace net {
|
||||||
|
class AuthChallengeInfo;
|
||||||
|
class URLRequest;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace mate {
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct Converter<const net::URLRequest*> {
|
||||||
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||||
|
const net::URLRequest* val);
|
||||||
|
};
|
||||||
|
|
||||||
|
template<>
|
||||||
|
struct Converter<const net::AuthChallengeInfo*> {
|
||||||
|
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
|
||||||
|
const net::AuthChallengeInfo* val);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace mate
|
||||||
|
|
||||||
|
#endif // ATOM_COMMON_NATIVE_MATE_CONVERTERS_NET_CONVERTER_H_
|
|
@ -316,6 +316,8 @@
|
||||||
'atom/common/native_mate_converters/gurl_converter.h',
|
'atom/common/native_mate_converters/gurl_converter.h',
|
||||||
'atom/common/native_mate_converters/image_converter.cc',
|
'atom/common/native_mate_converters/image_converter.cc',
|
||||||
'atom/common/native_mate_converters/image_converter.h',
|
'atom/common/native_mate_converters/image_converter.h',
|
||||||
|
'atom/common/native_mate_converters/net_converter.cc',
|
||||||
|
'atom/common/native_mate_converters/net_converter.h',
|
||||||
'atom/common/native_mate_converters/string16_converter.h',
|
'atom/common/native_mate_converters/string16_converter.h',
|
||||||
'atom/common/native_mate_converters/v8_value_converter.cc',
|
'atom/common/native_mate_converters/v8_value_converter.cc',
|
||||||
'atom/common/native_mate_converters/v8_value_converter.h',
|
'atom/common/native_mate_converters/v8_value_converter.h',
|
||||||
|
|
Loading…
Reference in a new issue