Add 'new-window' event for <webview>

This commit is contained in:
Cheng Zhao 2014-10-25 13:21:09 +08:00
parent d8447524cb
commit 194ed3884c
4 changed files with 27 additions and 8 deletions

View file

@ -78,6 +78,21 @@ bool WebContents::AddMessageToConsole(content::WebContents* source,
return true;
}
bool WebContents::ShouldCreateWebContents(
content::WebContents* web_contents,
int route_id,
WindowContainerType window_container_type,
const base::string16& frame_name,
const GURL& target_url,
const std::string& partition_id,
content::SessionStorageNamespace* session_storage_namespace) {
base::ListValue args;
args.AppendString(target_url.spec());
args.AppendString(partition_id);
Emit("new-window", args);
return false;
}
void WebContents::CloseContents(content::WebContents* source) {
Emit("close");
}
@ -210,14 +225,8 @@ void WebContents::WillAttach(content::WebContents* embedder_web_contents,
content::WebContents* WebContents::CreateNewGuestWindow(
const content::WebContents::CreateParams& create_params) {
auto web_contents = content::WebContents::Create(create_params);
// TODO Currently we just retain the web_contents on V8's heap, which will be
// garbage collected later, we should provide a way to let users make use of
// this WebContents.
mate::Handle<WebContents> managed = CreateFrom(
v8::Isolate::GetCurrent(), web_contents);
managed->storage_.reset(web_contents);
return web_contents;
NOTREACHED() << "Should not create new window from guest";
return nullptr;
}
void WebContents::DidAttach() {

View file

@ -93,6 +93,14 @@ class WebContents : public mate::EventEmitter,
const base::string16& message,
int32 line_no,
const base::string16& source_id) override;
bool ShouldCreateWebContents(
content::WebContents* web_contents,
int route_id,
WindowContainerType window_container_type,
const base::string16& frame_name,
const GURL& target_url,
const std::string& partition_id,
content::SessionStorageNamespace* session_storage_namespace) override;
void CloseContents(content::WebContents* source) override;
content::WebContents* OpenURLFromTab(
content::WebContents* source,

View file

@ -10,6 +10,7 @@ supportedWebViewEvents = [
'did-stop-loading'
'did-get-redirect-request'
'console-message'
'new-window'
'close'
'crashed'
'destroyed'

View file

@ -10,6 +10,7 @@ WEB_VIEW_EVENTS =
'did-stop-loading': []
'did-get-redirect-request': ['oldUrl', 'newUrl', 'isMainFrame']
'console-message': ['level', 'message', 'line', 'sourceId']
'new-window': ['url', 'partitionId']
'close': []
'crashed': []
'destroyed': []