Index: docs/mojo_in_chromium.md |
diff --git a/docs/mojo_in_chromium.md b/docs/mojo_in_chromium.md |
index b9919e22414936149e81fb477ef67bf7ee6843aa..0823e699e92f1f1b7117c58ac81b3b263a9d87a1 100644 |
--- a/docs/mojo_in_chromium.md |
+++ b/docs/mojo_in_chromium.md |
@@ -154,7 +154,7 @@ to any Mojo service. |
For illustrative purposes only, we can create a message pipe and bind an |
`InterfacePtr` to one end as follows: |
-``` |
+```cpp |
mojo::MessagePipe pipe; |
mojo::InterfacePtr<frob::Frobinator> frobinator; |
frobinator.Bind( |
@@ -184,7 +184,7 @@ see later, a first-class concept in Mojom interface definitions. |
As with `InterfacePtr<T>`, we can manually bind an `InterfaceRequest<T>` to a |
pipe endpoint: |
-``` |
+```cpp |
mojo::MessagePipe pipe; |
mojo::InterfacePtr<frob::Frobinator> frobinator; |
@@ -208,7 +208,7 @@ Defined in |
`mojo::GetProxy<T>` is the function you will most commonly use to create a new |
message pipe. Its signature is as follows: |
-``` |
+```cpp |
template <typename T> |
mojo::InterfaceRequest<T> GetProxy(mojo::InterfacePtr<T>* ptr); |
``` |
@@ -218,7 +218,7 @@ This function creates a new message pipe, binds one end to the given |
which it then returns. Equivalent to the sample code just above is the following |
snippet: |
-``` |
+```cpp |
mojo::InterfacePtr<frob::Frobinator> frobinator; |
mojo::InterfaceRequest<frob::Frobinator> frobinator_request = |
mojo::GetProxy(&frobinator); |
@@ -237,7 +237,7 @@ taken from a passed `InterfaceRequest<T>`. |
A common usage pattern looks something like this: |
-``` |
+```cpp |
#include "components/frob/public/interfaces/frobinator.mojom.h" |
#include "third_party/mojo/src/mojo/public/cpp/bindings/binding.h" |
#include "third_party/mojo/src/mojo/public/cpp/bindings/interface_request.h" |
@@ -258,7 +258,7 @@ class FrobinatorImpl : public frob::Frobinator { |
And then we could write some code to test this: |
-``` |
+```cpp |
// Fun fact: The bindings generator emits a type alias like this for every |
// interface type. frob::FrobinatorPtr is an InterfacePtr<frob::Frobinator>. |
frob::FrobinatorPtr frobinator; |
@@ -425,7 +425,8 @@ First create a new `//components/hello` directory. Inside this directory we're |
going to add the following files: |
**components/hello/main.cc** |
-``` |
+ |
+```cpp |
#include "base/logging.h" |
#include "third_party/mojo/src/mojo/public/c/system/main.h" |
@@ -436,6 +437,7 @@ MojoResult MojoMain(MojoHandle shell_handle) { |
``` |
**components/hello/BUILD.gn** |
+ |
``` |
import("//mojo/public/mojo_application.gni") |
@@ -484,7 +486,8 @@ least one service to connecting applications. |
Let's update `main.cc` with the following contents: |
**components/hello/main.cc** |
-``` |
+ |
+```cpp |
#include "components/hello/hello_app.h" |
#include "mojo/application/public/cpp/application_runner.h" |
#include "third_party/mojo/src/mojo/public/c/system/main.h" |
@@ -501,6 +504,7 @@ want -- a `mojo::ApplicationRunner` constructed over a |
the shell. We'll add some new files to the app as well: |
**components/hello/public/interfaces/greeter.mojom** |
+ |
``` |
module hello; |
interface Greeter { |
@@ -512,6 +516,7 @@ Note the new arrow syntax on the `Greet` method. This indicates that the caller |
expects a response from the service. |
**components/hello/public/interfaces/BUILD.gn** |
+ |
``` |
import("//third_party/mojo/src/mojo/public/tools/bindings/mojom.gni") |
@@ -523,7 +528,8 @@ mojom("interfaces") { |
``` |
**components/hello/hello_app.h** |
-``` |
+ |
+```cpp |
#ifndef COMPONENTS_HELLO_HELLO_APP_H_ |
#define COMPONENTS_HELLO_HELLO_APP_H_ |
@@ -559,7 +565,8 @@ class HelloApp : public mojo::ApplicationDelegate, |
**components/hello/hello_app.cc** |
-``` |
+ |
+```cpp |
#include "base/macros.h" |
#include "components/hello/hello_app.h" |
#include "mojo/application/public/cpp/application_connection.h" |
@@ -616,6 +623,7 @@ And finally we need to update our app's `BUILD.gn` to add some new sources and |
dependencies: |
**components/hello/BUILD.gn** |
+ |
``` |
import("//mojo/public/mojo_application.gni") |
@@ -664,7 +672,8 @@ which can connect to one or more applications-under-test. |
First let's introduce some test code: |
**components/hello/hello_apptest.cc** |
-``` |
+ |
+```cpp |
#include "base/bind.h" |
#include "base/callback.h" |
#include "base/logging.h" |
@@ -780,7 +789,7 @@ for additional clarity. |
We could have instead written this code as: |
-``` |
+```cpp |
mojo::URLRequestPtr app_url = mojo::URLRequest::New(); |
app_url->url = "mojo::hello"; |
@@ -835,15 +844,19 @@ Let's modify `ChromeContentBrowserClient::RegisterInProcessMojoApplications` |
(in `//chrome/browser/chrome_content_browser_client.cc`) by adding the following |
code: |
- apps->insert(std::make_pair(GURL("mojo:hello"), |
- base::Bind(&HelloApp::CreateApp))); |
+```cpp |
+apps->insert(std::make_pair(GURL("mojo:hello"), |
+ base::Bind(&HelloApp::CreateApp))); |
+``` |
you'll also want to add the following convenience method to your `HelloApp` |
definition in `//components/hello/hello_app.h`: |
- static scoped_ptr<mojo::ApplicationDelegate> HelloApp::CreateApp() { |
- return scoped_ptr<mojo::ApplicationDelegate>(new HelloApp); |
- } |
+```cpp |
+static scoped_ptr<mojo::ApplicationDelegate> HelloApp::CreateApp() { |
+ return scoped_ptr<mojo::ApplicationDelegate>(new HelloApp); |
+} |
+``` |
This introduces a dependency from `//chrome/browser` on to |
`//components/hello:lib`, which you can add to the `"browser"` target's deps in |
@@ -862,7 +875,7 @@ shell proxy, but the vast majority of Chromium code doesn't yet belong to a Mojo |
application. So how do we use an app's services from arbitrary browser code? We |
use `content::MojoAppConnection`, like this: |
-``` |
+```cpp |
#include "base/bind.h" |
#include "base/logging.h" |
#include "components/hello/public/interfaces/greeter.mojom.h" |
@@ -930,7 +943,7 @@ We can also connect to Mojo apps from a `RenderFrame`. This is made possible by |
`RenderFrame`'s `GetServiceRegistry()` interface. The `ServiceRegistry` can be |
used to acquire a shell proxy and in turn connect to an app like so: |
-``` |
+```cpp |
void GreetWorld(content::RenderFrame* frame) { |
mojo::ShellPtr shell; |
frame->GetServiceRegistry()->ConnectToRemoteService( |