OLD | NEW |
1 <style> | 1 <style> |
2 .note::before { | 2 .note::before { |
3 content: 'Note: '; | 3 content: 'Note: '; |
4 font-variant: small-caps; | 4 font-variant: small-caps; |
5 font-style: italic; | 5 font-style: italic; |
6 } | 6 } |
7 | 7 |
8 .doc h1 { | 8 .doc h1 { |
9 margin: 0; | 9 margin: 0; |
10 } | 10 } |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 return nullptr; // Not a known host; no special access. | 111 return nullptr; // Not a known host; no special access. |
112 ``` | 112 ``` |
113 | 113 |
114 and if a factory knows how to handle a host (returns a `WebUIFactoryFunction`), | 114 and if a factory knows how to handle a host (returns a `WebUIFactoryFunction`), |
115 the navigation machinery [grants the renderer process WebUI | 115 the navigation machinery [grants the renderer process WebUI |
116 bindings](#bindings) via the child security policy. | 116 bindings](#bindings) via the child security policy. |
117 | 117 |
118 ```c++ | 118 ```c++ |
119 // RenderFrameHostImpl::AllowBindings(): | 119 // RenderFrameHostImpl::AllowBindings(): |
120 if (bindings_flags & BINDINGS_POLICY_WEB_UI) { | 120 if (bindings_flags & BINDINGS_POLICY_WEB_UI) { |
121 » ChildProcessSecurityPolicyImpl::GetInstance()->GrantWebUIBindings( | 121 ChildProcessSecurityPolicyImpl::GetInstance()->GrantWebUIBindings( |
122 » » » GetProcess()->GetID()); | 122 GetProcess()->GetID()); |
123 } | 123 } |
124 ``` | 124 ``` |
125 | 125 |
126 The factory creates a [`WebUIController`](#WebUIController) for a tab. | 126 The factory creates a [`WebUIController`](#WebUIController) for a tab. |
127 Here's an example: | 127 Here's an example: |
128 | 128 |
129 ```c++ | 129 ```c++ |
130 // Controller for chrome://donuts. | 130 // Controller for chrome://donuts. |
131 class DonutsUI : public content::WebUIController { | 131 class DonutsUI : public content::WebUIController { |
132 public: | 132 public: |
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
442 } | 442 } |
443 ``` | 443 ``` |
444 | 444 |
445 This method is basically just a | 445 This method is basically just a |
446 [`CallJavascriptFunction()`](#CallJavascriptFunction) wrapper that calls a | 446 [`CallJavascriptFunction()`](#CallJavascriptFunction) wrapper that calls a |
447 global "cr.webUIResponse" method with a success value of false. | 447 global "cr.webUIResponse" method with a success value of false. |
448 | 448 |
449 ```c++ | 449 ```c++ |
450 // WebUIMessageHandler::RejectJavascriptCallback(): | 450 // WebUIMessageHandler::RejectJavascriptCallback(): |
451 CallJavascriptFunction("cr.webUIResponse", callback_id, base::Value(false), | 451 CallJavascriptFunction("cr.webUIResponse", callback_id, base::Value(false), |
452 » » » » » » » » » »
» response); | 452 response); |
453 ``` | 453 ``` |
454 | 454 |
455 See also: [`ResolveJavascriptCallback`](#ResolveJavascriptCallback) | 455 See also: [`ResolveJavascriptCallback`](#ResolveJavascriptCallback) |
456 | 456 |
457 <a name="ResolveJavascriptCallback"></a> | 457 <a name="ResolveJavascriptCallback"></a> |
458 ### WebUIMessageHandler::ResolveJavascriptCallback() | 458 ### WebUIMessageHandler::ResolveJavascriptCallback() |
459 | 459 |
460 This method is called in response to | 460 This method is called in response to |
461 [`cr.sendWithPromise()`](#cr_sendWithPromise) to fulfill an issued Promise, | 461 [`cr.sendWithPromise()`](#cr_sendWithPromise) to fulfill an issued Promise, |
462 often with a value. This results in runnings any fulfillment (first) callbacks | 462 often with a value. This results in runnings any fulfillment (first) callbacks |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 if (enabled_bindings_ & BINDINGS_POLICY_WEB_UI) | 496 if (enabled_bindings_ & BINDINGS_POLICY_WEB_UI) |
497 WebUIExtension::Install(frame_); | 497 WebUIExtension::Install(frame_); |
498 ``` | 498 ``` |
499 | 499 |
500 If the bindings exist, a global `chrome.send()` function is exposed to the | 500 If the bindings exist, a global `chrome.send()` function is exposed to the |
501 renderer: | 501 renderer: |
502 | 502 |
503 ```c++ | 503 ```c++ |
504 // WebUIExtension::Install(): | 504 // WebUIExtension::Install(): |
505 v8::Local<v8::Object> chrome = | 505 v8::Local<v8::Object> chrome = |
506 » » GetOrCreateChromeObject(isolate, context->Global()); | 506 GetOrCreateChromeObject(isolate, context->Global()); |
507 chrome->Set(gin::StringToSymbol(isolate, "send"), | 507 chrome->Set(gin::StringToSymbol(isolate, "send"), |
508 » » » » » » gin::CreateFunctionTemplate( | 508 gin::CreateFunctionTemplate( |
509 » » » » » » » » isolate, base::B
ind(&WebUIExtension::Send))->GetFunction()); | 509 isolate, base::Bind(&WebUIExtension::Send))->GetFunction()); |
510 ``` | 510 ``` |
511 | 511 |
512 The `chrome.send()` method takes a message name and argument list. | 512 The `chrome.send()` method takes a message name and argument list. |
513 | 513 |
514 ```js | 514 ```js |
515 chrome.send('messageName', [arg1, arg2, ...]); | 515 chrome.send('messageName', [arg1, arg2, ...]); |
516 ``` | 516 ``` |
517 | 517 |
518 The message name and argument list are serialized to JSON and sent via the | 518 The message name and argument list are serialized to JSON and sent via the |
519 `ViewHostMsg_WebUISend` IPC message from the renderer to the browser. | 519 `ViewHostMsg_WebUISend` IPC message from the renderer to the browser. |
520 | 520 |
521 ```c++ | 521 ```c++ |
522 // In the renderer (WebUIExtension::Send()): | 522 // In the renderer (WebUIExtension::Send()): |
523 render_view->Send(new ViewHostMsg_WebUISend(render_view->GetRoutingID(), | 523 render_view->Send(new ViewHostMsg_WebUISend(render_view->GetRoutingID(), |
524 » » » » » » » » » »
» » » » » » » » » »
» » frame->GetDocument().Url(), | 524 frame->GetDocument().Url(), |
525 » » » » » » » » » »
» » » » » » » » » »
» » message, *content)); | 525 message, *content)); |
526 ``` | 526 ``` |
527 ```c++ | 527 ```c++ |
528 // In the browser (WebUIImpl::OnMessageReceived()): | 528 // In the browser (WebUIImpl::OnMessageReceived()): |
529 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend) | 529 IPC_MESSAGE_HANDLER(ViewHostMsg_WebUISend, OnWebUISend) |
530 ``` | 530 ``` |
531 | 531 |
532 The browser-side code does a map lookup for the message name and calls the found | 532 The browser-side code does a map lookup for the message name and calls the found |
533 callback with the deserialized arguments: | 533 callback with the deserialized arguments: |
534 | 534 |
535 ```c++ | 535 ```c++ |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
667 let localLinks = Array.from(document.querySelectorAll('a[href^="#"]')); | 667 let localLinks = Array.from(document.querySelectorAll('a[href^="#"]')); |
668 let hrefs = localLinks.map(a => a.href.split('#')[1]); | 668 let hrefs = localLinks.map(a => a.href.split('#')[1]); |
669 | 669 |
670 hrefs.forEach(href => { | 670 hrefs.forEach(href => { |
671 if (names.includes(href)) | 671 if (names.includes(href)) |
672 console.info('found: ' + href); | 672 console.info('found: ' + href); |
673 else | 673 else |
674 console.error('broken href: ' + href); | 674 console.error('broken href: ' + href); |
675 }) | 675 }) |
676 </script> | 676 </script> |
OLD | NEW |